generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

"Humanoid is not a valid member of Hat", Impossible. Read.

Previous Thread :: Next Thread 
ianfulton is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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 is not online. 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 is not online. LuaJake
Joined: 20 Jun 2013
Total Posts: 2009
27 Feb 2015 03:40 PM
That's fine :)
Report Abuse
ianfulton is not online. 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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
27 Feb 2015 03:45 PM
Look up numeric for loops on the wiki.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image