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

Script Cloning not working?

I made a script so that it would clone a script into the playergui but it doesnt work. I've tried 3 different ways and they all close it to 1 player instead of all the players. I've tried several times and its starting to get aggravating. I made the same code 3 different ways but they all failed.

Code1:

function endround()
	local roundui= serverstore.gamestuff.UI:FindFirstChild("endUI"):Clone()
local players = game.Players:GetChildren()
x = 1,#players
if players[x] ~= nil then
	local pgui = players[x]:FindFirstChild"PlayerGui"
	roundui.Parent = pgui
	roundui.Disabled = false
	
end
end


Code2:

function endround()
local roundui= serverstore.gamestuff.UI:FindFirstChild("endUI"):Clone()
wait()
	local peeps = {}
for _, players in pairs (game.Players:GetChildren()) do
	table.insert(peeps,players)
end

for i, player in pairs (peeps) do
	if player and  player.Character  then
		
roundui.Parent = player.PlayerGui
roundui.Disabled = false
	end
end
	end

Code3:

function endround()
local roundui= serverstore.gamestuff.UI:FindFirstChild("endUI"):Clone()
for _, plr in pairs (game.Players:GetChildren()) do
	roundui.Parent = plr.PlayerGui
roundui.Disabled = false
end
end

4 comments

0

Just put the script in StarterGui.

0

The code above is in a serverscriptservice and I can't activate scripts from client directly from there.

0

What? All you want is a localScript to be put into the PlayerGui, right?

0

yes. But I cant check the clients Player GUI using the server scripts. I've tried it 20 times. im pretty sure that doesnt work. And also I want the code activated @ a certain time.

1 answer

function endround()
for _, plr in pairs (game.Players:GetChildren()) do
local roundui= serverstore.gamestuff.UI:FindFirstChild("endUI"):Clone()
    roundui.Parent = plr.PlayerGui
roundui.Disabled = false
end
end

You was only making one clone and then trying to send that one clone to several players, you need to create a new clone every time you index another player.

All the best.

4 comments

0

makes sense

0

how would I go about doing that?

0

My answer has the correct code to use, you can see that the clone is within 'for _, plr in pairs (game.Players:GetChildren()) do'.

0

For what you want to do though, I recommend using RemoteFunctions (http://wiki.roblox.com/index.php?title=API:Class/RemoteFunction) instead of parenting a local script into a player's PlayerGui (unless It's really long and/or the local script has instances attached)

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