I have a gui that when the spawn is touched, it prints the user's roblox avatar image, but the script isn't working. Help please.
function onTouched(hit) if hit.Parent:GetPlayerFromCharacter('Humanoid') then local userid = hit.Parent.UserId game.Workspace.LocalUserId.Value = userid wait(0.1) game.Workspace.join.SurfaceGui.ImageLabel.Image =('http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&Format=Png&userId='userid) end end script.Parent.Touched:connect(onTouched)
Thanks
EDIT I answered too soon!
There's a few more things we need to change.
GetPlayerFromCharacter is a method of the Players service, not hit.Parent (that's the character). UserId is a property of the player, NOT the character. You pass in the string "Humanoid" whereas we need to pass in the parent of the object (say a leg or an arm) which is the character.
Here is the wiki article on player UserId's.
local players = game:GetService("Players") function onTouched(hit) local player = players:GetPlayerFromCharacter(hit.Parent) if player then -- This will only run if our player variable exists. local userid = player.UserId game.Workspace.LocalUserId.Value = userid wait(0.1) game.Workspace.join.SurfaceGui.ImageLabel.Image =('http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&Format=Png&userId='..userid) end end script.Parent.Touched:connect(onTouched)
In order to append or concatenate strings in lua you want to use the ..
operator.
Here's how you do that with your code.
game.Workspace.join.SurfaceGui.ImageLabel.Image =('http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&Format=Png&userId='..userid)
Some examples.
print("my ".."name is ".."kools") -- my name is kools local var = 3 print("# is "..var) -- # is 3