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

Script save problem when a player joins a game?

So I was testing out my script and there was some type of a problem joining in the game where the script doesn't load up whenever a player joins a server until they reset for it to work. Although it works sometimes, it doesn't do it always.

game.Players.PlayerAdded:connect(function(player)
	local currentlevel = player:WaitForChild("leaderstats"):WaitForChild("Level")
	player.CharacterAdded:connect(function(char)
		if currentlevel.Value >= 2 then
			script.Parent.Parent.StarterGui.Stamina.Handler.Disabled = false
		end
		if currentlevel.Value >= 3 then
			script.Parent.Parent.StarterGui.DoubleJump.Disabled = false
		end
		if currentlevel.Value >= 4 then
			player.Backpack.ScriptStorage.PlayerMovement.ForwardDash.Disabled = false
		end
	char.Humanoid.Died:connect(function()
		if currentlevel.Value >= 2 then
			script.Parent.Parent.StarterGui.Stamina.Handler.Disabled = false
		end
		if currentlevel.Value >= 3 then
			script.Parent.Parent.StarterGui.DoubleJump.Disabled = false
		end
		if currentlevel.Value >= 4 then
			player.Backpack.ScriptStorage.PlayerMovement.ForwardDash.Disabled = false
		end
	end)
	end)
end)

3 comments

0

You are using local script?

0

No it's in the ServerScriptService as a normal Script

0

You cannot access playergui with server script.

1 answer

✓ Accepted answer

You need to use Local Script to access Player Gui's You cannot edit PlayerGui's with StarterGui

You can see PlayerGui in Roblox Wiki > Roblox Wiki Page - PlayerGui

And you can see PlayerGui vs StarterGui in Roblox Wiki > Roblox Wiki Page - Player vs. Starter GUIs

Also you can see StarterGui in Roblox Wiki > Roblox Wiki Page - StarterGui

You can use this:


-- Local Script > put this on GUI --

repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local char = player.Character

local currentlevel = player:WaitForChild("leaderstats"):WaitForChild("Level")

function update()
	if currentlevel.Value >= 2 then
		script.Parent.Stamina.Handler.Disabled = false
	end
	if currentlevel.Value >= 3 then
		script.Parent.DoubleJump.Disabled = false
	end
	if currentlevel.Value >= 4 then
		player.Backpack.ScriptStorage.PlayerMovement.ForwardDash.Disabled = false
	end
end

while true do
	update()
	wait(0.5)
end

Hope it helped! Good luck into your game!

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