Why is My Character added event not working?

So pretty much when the Players value gets set to athell the script doesn’t move the player to the hell spawn. Script is pretty self explanatory I would highly appreciate some help.

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	Folder.Parent = player
	Folder.Name = "PlayerInfo"
	
	local AtHell = Instance.new("BoolValue")
	AtHell.Parent = Folder
	AtHell.Name = "AtHell"
	AtHell.Value = false
	
	local CommandRunning = Instance.new("BoolValue")
	CommandRunning.Parent = Folder
	CommandRunning.Name = "CommandRunning"
	CommandRunning.Value = false
	
	player.CharacterAdded:Connect(function(character)
		if player.PlayerInfo.AtHell.Value == true then
			character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.HellTeleport.CFrame
		else
			character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.Spawn.CFrame
		end
	end)
end)

1 Like

Did u check that AtHell was being set to true when the character respawns

1 Like

yes I checked to make sure AtHell is set to true once the player has entered hell and it stays true but they go to the regular spawn

Try adding a little bit of delay to see if the spawnpoint is overriding the HellTeleport Cframe

	player.CharacterAdded:Connect(function(character)
		if player.PlayerInfo.AtHell.Value == true then
        task.wait(2)
			character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.HellTeleport.CFrame
		else
			character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.Spawn.CFrame
		end
	end)

Hmm, is HumanoidRootPart loaded ? If it’s not, your code should be yielded.

Hmm, I don’t think it should override. Because there is if-else statement so only if the AtHell Value is true, it would teleport.

the spawn isn’t actually a spawn it’s just a random part named spawn

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
	local Folder = Instance.new("Folder")
	Folder.Parent = player
	Folder.Name = "PlayerInfo"
	
	local AtHell = Instance.new("BoolValue")
	AtHell.Parent = Folder
	AtHell.Name = "AtHell"
	AtHell.Value = false
	
	local CommandRunning = Instance.new("BoolValue")
	CommandRunning.Parent = Folder
	CommandRunning.Name = "CommandRunning"
	CommandRunning.Value = false
	
	player.CharacterAdded:Connect(function(character)
    wait()
		if player.PlayerInfo.AtHell.Value == true then
			character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.HellTeleport.CFrame
		else
			character:WaitForChild("HumanoidRootPart").CFrame = game.Workspace.Spawn.CFrame
		end
	end)
end)

I think adding a wait() should do the trick. Because maybe for a second, value is false, hence wait() would be safe.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.