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

How to do an if statement if player loadscharacter??

Asked by 1 year ago
Edited 1 year ago

I want to make an if statement testing if a player load character. The issue I keep getting with my if statement is that when I join the game I keep respawning nonstop. Script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Char)
        if Player:LoadCharacter() then--if statement broken
            wait(6)
            Player.PlayerGui.MainUI.Enabled = true
            Player.PlayerGui.MoneyGui.Enabled = true
        end
        end)
        end)

Gui button

game.Players.PlayerAdded:Connect(function(player)
    player:GetChildren(player)
    script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.LoadPlayer:FireServer()-- make a remote event named LoadPlayer
        player:LoadCharacter()
    end)


    end)

2 answers

Log in to vote
0
Answered by
s_21 74
1 year ago

you can use the Char.Parent property instead of Player:LoadCharacter() to test if the character has been added to the game:

game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
if Char.Parent ~= nil then
wait(6)
Player.PlayerGui.MainUI.Enabled = true
Player.PlayerGui.MoneyGui.Enabled = true
end
end)
end)

'LoadCharacter' function is blocking, so it halts the script until the character is fully loaded. This then causes an infinite loop as the character is not fully loaded when the 'if' statement is called

0
Still won't work when I clicked the load character button in my game the gui still didn't go visible. 666_brithday 103 — 1y
Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

Here a solution try using a remote event

This is an example that your gui button script might be

script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.LoadPlayer:FireServer()-- make a remote event named LoadPlayer
--Put your load character code here

Script in serverscriptservice

game.ReplicatedStorage.LoadPlayer.OnServerEvent:Connect(function(plr)
wait(6) -- wait here make sure there character is fully loaded
--Put your gui stuff here that you want visible

Let me know if any errors NOT tested Hope this helps!!

0
Didn't work also you spelled script wrong 666_brithday 103 — 1y
0
I fixed it can you show your whole script theking66hayday 841 — 1y
0
ok my post is updated 666_brithday 103 — 1y
0
ok i don't think you can do loadplayer in a local script in a gui. Make another remote event for the loadplayer theking66hayday 841 — 1y
0
Still did not work 666_brithday 103 — 1y

Answer this question