Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

GUI is not moving from serverstorage to playergui?

Asked by 8 years ago

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:

01function 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
09end
10 
11script.Parent.Touched:connect(onTouch)

Help?

2 answers

Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
8 years ago

Look at the comments I made.

01function 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
10end
11 
12script.Parent.Touched:connect(onTouch)

Hope this helps ;)

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

You need :GetService() with ServerStorage

Answer this question