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

Working in Roblox studio but not in Game?

This is the full script, what I'm trying to do is to make the GUI only appear only once which is when the player joins the game, it is working in Roblox Studio but not in actual Roblox Game.

function onPlayerEntered(newPlayer) 
	wait(.1) 
	local stats = Instance.new("IntValue") 
	stats.Name = "leaderstats"
	local stats2 = Instance.new("IntValue") 
	stats2.Name = "Tycoon" 

	stats2.Parent = newPlayer 
	stats.Parent = newPlayer 		
	
	wait(.1)
	local clone=game.ReplicatedStorage:FindFirstChild("GUIs"):FindFirstChild("JoinGui")
	local player = game.Players.LocalPlayer	
	clone.Parent = player.PlayerGui

end

game.Players.ChildAdded:connect(onPlayerEntered) 

3 comments

0

Is this a Script or a LocalScript?

0

if it works in studio im guessing it's not a script..

0

game.Players.LocalPlayer, can only be used in a LocalScript

1 answer

✓ Accepted answer
--If your planing to use the onPlayerEntered event then you might as well stick to Script aka Server Sided scripting.
--Do not just randomly add **LocalPlayer** and mix it up with server side and client side.
function onPlayerEntered(newPlayer) 
    wait(.1) 
    local stats = Instance.new("IntValue") 
    stats.Name = "leaderstats"
    local stats2 = Instance.new("IntValue") 
    stats2.Name = "Tycoon" 

    stats2.Parent = newPlayer 
    stats.Parent = newPlayer        

    wait(.1)
    local clone=game.ReplicatedStorage:FindFirstChild("GUIs"):FindFirstChild("JoinGui")
    local player = newPlayer -- I have changed it to newPlayer since you had the argument setup since before. 
    clone.Parent = player.PlayerGui

end

game.Players.PlayerAdded:connect(onPlayerEntered) --Also I am changing it to PlayerAdded
--if this helped leave a upvote thanks.

2 comments

0

Thanks alot!

0

Np

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