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 2 years ago
Edited 2 years 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:

1game.Players.PlayerAdded:Connect(function(Player)
2    Player.CharacterAdded:Connect(function(Char)
3        if Player:LoadCharacter() then--if statement broken
4            wait(6)
5            Player.PlayerGui.MainUI.Enabled = true
6            Player.PlayerGui.MoneyGui.Enabled = true
7        end
8        end)
9        end)

Gui button

1game.Players.PlayerAdded:Connect(function(player)
2    player:GetChildren(player)
3    script.Parent.MouseButton1Click:Connect(function()
4    game.ReplicatedStorage.LoadPlayer:FireServer()-- make a remote event named LoadPlayer
5        player:LoadCharacter()
6    end)
7 
8 
9    end)

2 answers

Log in to vote
0
Answered by
s_21 74
2 years ago

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

1game.Players.PlayerAdded:Connect(function(Player)
2Player.CharacterAdded:Connect(function(Char)
3if Char.Parent ~= nil then
4wait(6)
5Player.PlayerGui.MainUI.Enabled = true
6Player.PlayerGui.MoneyGui.Enabled = true
7end
8end)
9end)

'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 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Here a solution try using a remote event

This is an example that your gui button script might be

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

Script in serverscriptservice

1game.ReplicatedStorage.LoadPlayer.OnServerEvent:Connect(function(plr)
2wait(6) -- wait here make sure there character is fully loaded
3--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 — 2y
0
I fixed it can you show your whole script theking66hayday 841 — 2y
0
ok my post is updated 666_brithday 103 — 2y
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 — 2y
0
Still did not work 666_brithday 103 — 2y

Answer this question