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

How to do an if statement if player loadscharacter??

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

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

1 comment

0

Still won't work when I clicked the load character button in my game the gui still didn't go visible.

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!!

5 comments

0

Didn't work also you spelled script wrong

0

I fixed it can you show your whole script

0

ok my post is updated

0

ok i don't think you can do loadplayer in a local script in a gui. Make another remote event for the loadplayer

0

Still did not work

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