I know... I just asked a question yesterday... I just suck with GUIs I guess... XD
Well, whats supposed to happen is when a player touches a brick a gui from ServerStorage gets moved from there to the PlayerGui. Now the output is helping but I don't understand how to fix it.
This is what the Output says:
Workspace.trigger.Script:5: attempt to index local 'plr' (a nil value) P.S - trigger is the Script I am trying to use to move the gui's parent.
The script:
01 | function onTouch(part) |
02 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) --find the character |
03 | if (humanoid ~ = nil ) then |
04 | local plr = game.Players:GetPlayerFromCharacter(humanoid) --get the player |
05 | local playgui = plr:WaitForChild( 'PlayerGui' ) --obtains the player's PlayerGui |
06 | game.ServerStorage.profoak.Parent = playgui --the gui was in serverstorage, now moving it to the playergui |
07 |
08 | end |
09 | end |
10 |
11 | script.Parent.Touched:connect(onTouch) |
Help?
Look at the comments I made.
01 | function onTouch(part) |
02 | local humanoid = part.Parent:FindFirstChild( "Humanoid" ) --find the character |
03 | if (humanoid ~ = nil ) then |
04 | local plr = game.Players:GetPlayerFromCharacter(part.Parent) --part.Name is the name of the player. |
05 | local playgui = plr:WaitForChild( 'PlayerGui' ) --obtains the player's PlayerGui |
06 | local item = game.ServerStorage.profoak --Made variable for the next line. |
07 | item:Clone().Parent = playgui --Instead of parenting, we should clone the parent so other players can get the gui. |
08 |
09 | end |
10 | end |
11 |
12 | script.Parent.Touched:connect(onTouch) |
Hope this helps ;)