ianfulton
|
  |
| Joined: 12 Apr 2011 |
| Total Posts: 98 |
|
|
| 27 Feb 2015 03:16 PM |
"Humanoid is not a valid member of Hat", Why?
local ting = true function onTouch(hit) local owner = script.Parent.Parent.Parent.Parent if hit.Parent.Humanoid ~= nil and ting == true then ting = false owner.Owner.Value = hit.Parent.Name wait(0.5) script.Parent.Transparency = 0.1 wait(0.5) script.Parent.Transparency = 0.2 wait(0.5) script.Parent.Transparency = 0.3 wait(0.5) script.Parent.Transparency = 0.4 wait(0.5) script.Parent.Transparency = 0.5 wait(0.5) script.Parent.Transparency = 0.6 wait(0.5) script.Parent.Transparency = 0.7 wait(0.5) script.Parent.Transparency = 0.8 wait(0.5) script.Parent.Transparency = 0.9 wait(0.5) script.Parent.Transparency = 1 wait(0.5) script.Parent:Remove() wait(15) ting = true
else if hit.Parent.Humanoid == nil and ting == true then ting = false print("Not a player") wait(15) ting = true end end end
script.Parent.Touched:connect(onTouch) |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2015 03:18 PM |
"if hit.Parent.Humanoid ~= nil " That will error if Humanoid is nil, since those classes are userdata, not tables. We have FindFirstChild for a reason. -_- |
|
|
| Report Abuse |
|
|
LuaJake
|
  |
| Joined: 20 Jun 2013 |
| Total Posts: 2009 |
|
|
| 27 Feb 2015 03:19 PM |
check to see if hit is a player
and also
wait(0.5) script.Parent.Transparency = 0.1 wait(0.5) script.Parent.Transparency = 0.2 wait(0.5) script.Parent.Transparency = 0.3 wait(0.5) script.Parent.Transparency = 0.4 wait(0.5) script.Parent.Transparency = 0.5 wait(0.5) script.Parent.Transparency = 0.6 wait(0.5) script.Parent.Transparency = 0.7 wait(0.5) script.Parent.Transparency = 0.8 wait(0.5) script.Parent.Transparency = 0.9 wait(0.5) script.Parent.Transparency = 1 wait(0.5)
that's messy
try this
for i = .1,1,.1 do wait(.5) script.Parent.Transparency = i end wait(.5) |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2015 03:21 PM |
And also, here "else if hit.Parent.Humanoid == nil and ting == true then" you should use "elseif", not "else if". This is Lua. But for this case do NOT check. If it isn't the first one, it is obviously the second one, so just use "else".
But do it like this
if ting then if foundHumanoid then --stuff else --stuff end end
And also, "~= nil" and "== true" makes the code unclean, and should not be used unless you know why you need it that way. Instead, use "if not Something" or "if Something".
http://wiki.roblox.com/index.php?title=Writing_Clean_Code |
|
|
| Report Abuse |
|
|
vividtrip
|
  |
| Joined: 14 Oct 2008 |
| Total Posts: 2890 |
|
|
| 27 Feb 2015 03:31 PM |
If checking for a player in a 'touched' script instead try game.Players:GetPlayerFromCharacter(hit.Parent), it's much cleaner and is more robust. Simply checking for a humanoid object should be avoided since if a player pushes an NPC into your part then it's going to assume the NPC is a player character, which could be an issue.
[PROFESSIONAL SEAGULL ENTHUSIAST AND TIME TRAVELER] |
|
|
| Report Abuse |
|
|
ianfulton
|
  |
| Joined: 12 Apr 2011 |
| Total Posts: 98 |
|
|
| 27 Feb 2015 03:39 PM |
| LuaJake and vividtrip, thanks! I'm sorry other dude, you just ticked me off. |
|
|
| Report Abuse |
|
|
LuaJake
|
  |
| Joined: 20 Jun 2013 |
| Total Posts: 2009 |
|
| |
|
ianfulton
|
  |
| Joined: 12 Apr 2011 |
| Total Posts: 98 |
|
|
| 27 Feb 2015 03:40 PM |
| Nobody even answered my question, anyway. It was because in a hat, there is "Handle" |
|
|
| Report Abuse |
|
|
ianfulton
|
  |
| Joined: 12 Apr 2011 |
| Total Posts: 98 |
|
|
| 27 Feb 2015 03:41 PM |
| LuaJake, whats with the .1,1,.1? How does that work? Transparency only has one number |
|
|
| Report Abuse |
|
|
|
| 27 Feb 2015 03:45 PM |
| Look up numeric for loops on the wiki. |
|
|
| Report Abuse |
|
|