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:

function onTouch(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid") --find the character
    if (humanoid ~= nil) then 
        local plr = game.Players:GetPlayerFromCharacter(humanoid) --get the player
        local playgui = plr:WaitForChild('PlayerGui') --obtains the player's PlayerGui
        game.ServerStorage.profoak.Parent = playgui--the gui was in serverstorage, now moving it to the playergui

    end
end

script.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.

function onTouch(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid") --find the character
    if (humanoid ~= nil) then 
        local plr = game.Players:GetPlayerFromCharacter(part.Parent) --part.Name is the name of the player.
        local playgui = plr:WaitForChild('PlayerGui') --obtains the player's PlayerGui
        local item = game.ServerStorage.profoak --Made variable for the next line.
    item:Clone().Parent = playgui --Instead of parenting, we should clone the parent so other players can get the gui.

    end
end

script.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