|
| 14 Jul 2013 03:15 PM |
Hello, I was wondering if you can tell me what is wrong with this script. It is yelling at me for line sixtrying to index plr.
function onTouched(hit) local Humanoid = hit.Parent:FindFirstChild("Humanoid") local hitname = hit.Parent.Name local plr = game.Players:FindFirstChild(hitname) local to = Instance.new("StringValue") local tycooncheck = plr:FindFirstChild("TycoonOwner") if Humanoid ~= nil then if tycooncheck == nil then to.Name = "TycoonOwner" to.Parent = plr to.Value = hitname elseif tycooncheck ~= nil then print("You Have A Tycoon Already! You Can Only Have One!") end end end
script.Parent.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:17 PM |
You have local plr = game.Players:FindFirstChild(hitname)
Should be local plr = game.Players:FindFirstChild(hit.name) |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:18 PM |
Oh and Name has to be capitalized local plr = game.Players:FindFirstChild(hit.Name) |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:19 PM |
| fail just noticed the hitname variable |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:21 PM |
| I have a variable that is hit.Parent.Name the name of the variable is hitname |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:22 PM |
try local plr = game.Players:getPlayerFromCharacter(hit.Parent) |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:27 PM |
| I think that worked... But it still yelled at me.... Hm. It is telling me it is a nil value, would it still do that even if I have that check for seeing if it is nil? |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:28 PM |
| And now it isn't working for a some reason. |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:31 PM |
| Yeah you need an if statement, you can't just assign variables without checking if they are there. |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:34 PM |
Like this
function onTouched(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then --First we see if Humanoid is a parent of hit local Humanoid = hit.Parent:FindFirstChild("Humanoid") --Then we assign Humanoid |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 03:34 PM |
| I do, though. It is seeing if it equals nil or not. If it does, then it creates it. If it does and it has a value it prints that you have one. If it isn't the correct one could you explain what one I need? |
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Jul 2013 04:01 PM |
| If no one can fugure it out then I can just put it in the model... I would like it if I could put it in the player though. |
|
|
| Report Abuse |
|
|
NVianney
|
  |
| Joined: 24 Mar 2012 |
| Total Posts: 173 |
|
|
| 14 Jul 2013 04:09 PM |
if (hit.Parent:findFirstChild("Humanoid") == nil then return end local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
|
|
|
| Report Abuse |
|
|
NVianney
|
  |
| Joined: 24 Mar 2012 |
| Total Posts: 173 |
|
|
| 14 Jul 2013 04:10 PM |
Fixed version:
if (hit.Parent:findFirstChild("Humanoid") == nil) then return end local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 04:19 PM |
| How would I implement that exactly? If that is checking if the humanoid exists then I have it already. Just in a different format. |
|
|
| Report Abuse |
|
|
NVianney
|
  |
| Joined: 24 Mar 2012 |
| Total Posts: 173 |
|
|
| 14 Jul 2013 04:24 PM |
I'll post the whole source code.
function onTouched(hit) local Humanoid = hit.Parent:FindFirstChild("Humanoid") if (Humanoid ~= nil) then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) local to = Instance.new("StringValue") local tycooncheck = plr:FindFirstChild("TycoonOwner") if tycooncheck == nil then to.Name = "TycoonOwner" to.Parent = plr to.Value = hit.Parent.Name elseif tycooncheck ~= nil then print("You Have A Tycoon Already! You Can Only Have One!") end end end
script.Parent.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 04:37 PM |
| Wow, that worked! So how does putting Humanoid ~= nil in ()'s fix it? |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2013 04:45 PM |
script.Parent.Touched:connect(function(hit) local H = hit.Parent:findFirstChild("Humanoid") if H ~= nil then local P = game.Players:GetPlayerFromCharacter(hit.Parent) if P ~= nil then P:Destroy() end end end)
Trust me. ;D |
|
|
| Report Abuse |
|
|