Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script save problem when a player joins a game?

Asked by
fr2013 88
5 years ago

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)
0
You are using local script? yHasteeD 1819 — 5y
0
No it's in the ServerScriptService as a normal Script fr2013 88 — 5y
0
You cannot access playergui with server script. yHasteeD 1819 — 5y

1 answer

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago

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!

Ad

Answer this question