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

Why am I not picking up anything in the output?

Okay so essentially I am saying if there is no such thing as the gravity controller then reload the character.

if not game.ReplicatedStorage:FindFirstChild("GravityController") then	
	game.Players.PlayerAdded:connect(function(player)
		wait(1)
	player:LoadCharacter()
	print("Player.Name..was Refreshed")
	end)
end

6 comments

0

PlayerAdded only fires when the player joins the game.

0

Try switching line 1 and 2

0

yeah but the gravity controller is not destroyed yet so how could it run?

0

Also is this in a local script or server script.

0

local

0

You have to always check if the gravity controller is missing. If it is then reload the character, and break the loop. You could use a while loop or a repeat until loop.

2 answers

This is because your not supposed to add a wait when the player joins because the player will already have joined within 0 seconds.WaitForChild

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
		local humanoid = character:FindFirstChild("Humanoid")

if not game.ReplicatedStorage:WaitForChild("GravityController") then  
    player:LoadCharacter()
    print("Player.Name..was Refreshed")
    end)
end

2 comments

0

I am not talking about when the player joins I am talking about if the gravity controllerscript is not there then it will refresh the player

0

Put your script in StarterPlayerScript

game:GetService('Players').PlayerAdded:Connect(function(plr)
	if not game:GetService('ReplicatedStorage'):FindFirstChild('GravityController') then
		wait(1)
		plr:LoadCharacter()
		print(plr.Name..' was refreshed!')
	end
end)

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