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

What is wrong with this script?

I made a simple script that is the base for thing later on, this script clones a GUI in a tool into PlayerGui but it didn't work. And there was no error either! so i couldn't solve the problem. Here is the script:

function Show()
	cloned = script.Parent:Clone()
	cloned.Parent = game.Players.Player1.PlayerGui
end
while true do
	Show()
end

1 answer

✓ Accepted answer

This script is a recipe for crashes. Currently it keeps cloning this script to the PlayerGui and from there the cloned scripts start cloning themselves too. I'd create a script with something like this.

function Show(player)
	local clone = game.ServerStorage.Script:Clone()
	clone.Parent = player.PlayerGui
end

game.Players.PlayerAdded:connect(Show(player))

Then put the script you want to copy into the ServerStorage and change it in the script. This way it will only run once. And if you want it to do it everytime a player spawns. Use the following script.

function Show(player)
	local clone = game.ServerStorage.Script:Clone()
	clone.Parent = player.PlayerGui
end

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(Show(player))
end)

3 comments

0

What if he needs to do that for everytime he spawns? The PlayerGui resets to what is inside the StarterGui each time you respawn.

0

If he needs to run that script everytime someone spawns, then he has to make his question more specific. It's that simple. Edit: I added another script that does it on each respawn.

0

It didn't work right away but with a few upgrades it worked well :)

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