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

if statements based gui-clone doesnt work in servers. any help?

the script is designed to clone a gui into the player's backpack if they dont already have it, but it doesnt seem to work in servers but it does in studio.

script.Parent.Touched:connect(function(hit)
	local character = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	
	if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and not player.PlayerGui:FindFirstChild("ClassSelection") then
		script.ClassSelection:Clone().Parent = player.PlayerGui
	end
end)

1 answer

✓ Accepted answer

Keep in mind that a player's PlayerGui is local to that player, and hence cannot be accessed by a server-side script. Create a remote function / event that the server-side script can call and have a local script listen for this notification and update the user interface accordingly.

[EDIT] For robustness, you should also check to make sure that player is non-nil, as any non-player controlled humanoid model that touches the part will break your script.

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