Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

GUI is not moving from serverstorage to playergui?

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

✓ Accepted answer

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 ;)

You need :GetService() with ServerStorage

This discussion is preserved as it was. New answers, comments, and votes are closed.