How do I improve this little script?

jeez mb sir my last reply ehhh

1 Like

No I dont think so. :confused: With the script i sent in the first message here it worked

If I read the topic’s purpose, your script kept killing the player on a loop because of the CharacterAdded.
Just take your script, maybe twist it a bit and remove CharacterAdded?

game.Players.PlayerAdded:Connect(function(Player)
	game.Players.RespawnTime = 0.2
	local char = Player.Character
    char:WaitForChild("Head"):Destroy()
end)

Yea but i want that it only happens 1 time and after 20 secs

In that case, have a 20 second delay.

game.Players.PlayerAdded:Connect(function(Player)
	game.Players.RespawnTime = 0.2
	local char = Player.Character
    task.delay(20, function()
        char:WaitForChild("Head"):Destroy()
	end)
end)
--I consider it good practise to define the services you use
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	print("Player Added!")
	Players.RespawnTime = .2 --this can be moved outside the function
	--keep in mind, their character may load before the script runs
	local Character = player.Character or player.CharacterAdded:Wait()
	--waiting for a maximum of 5 seconds, without yielding the script
	local Head = Character:WaitForChild("Head", 5)
	task.wait(4) --so it can be seen
	if Head then
		--I had to use Character.Head instead of Head(no idea why)
		Character.Head:Destroy()
	end
end)

This wont work for some reason :confused:

It’ll just remove the head

Fixed it, for some reason Character:WaitForChild("Head", 5) wasn’t returning the actual head instance.

This isn’t my topic but I’ve already told the topic creator the exact same answer:

game.Players.PlayerAdded:Connect(function(Player)
    task.delay(20, function()
       Player.Character:WaitForChild("Head"):Destroy()
    end)
end)
game.Players.PlayerAdded:Connect(function(Player)
	game.Players.RespawnTime = 0.2
	local Character = Player.Character or Player.CharacterAdded:Wait()
	Character:WaitForChild("Head"):Destroy()
end)

Man please read the replies I’ve sent before sending the exact same thing I’ve sent

It doesn’t reset my character.

Just do this. It works fine for me?

game.Players.PlayerAdded:Connect(function(Player)
    task.delay(20, function()
        Player.Character.Head:Destroy()
    end)
end)
game.Players.PlayerAdded:Connect(function(player)
	print('Player Added !')
	local char = player.Character or player.CharacterAdded:Wait()
	player:LoadCharacter()
	wait(5)
	char.Head:Remove()
end)

Doesn’t work for me. Don’t mind the character reset at the start, that’s from another script.

I don’t see any problem???
Are you even waiting 20 seconds
Also where did you put the script?

You don’t see a problem? It’s not resetting, thats the problem :smiley:
I waited 20 seconds yes.

Workspace, like I mentioned above.

Try putting a print in the PlayerAdded function and check if it prints or not

Doesn’t work for me. :confused: Idk why