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

How do you make a script that kicks after a humanoid is dead?

So I have a boss fight place (1 player server) and I want to insert a script into the humanoid of the boss so that when it dies, after 30 seconds it kicks you out of the game with a custom kick message, how do I make such thing?

P.S. I'm a terrible scripter so please explain thoroughly!

1 comment

0

Please try attempting it, and if it doesn't work you can come back and ask for help to make the script function the way you want it to.

2 answers

✓ Accepted answer

Hey! I noticed the last answer was not working for you so I made a revised version. Put this in a normal Script inside of the NPC:

local hum = script.Parent.Humanoid
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		hum.Died:Connect(function(Death)
			wait(30)
			Player:Kick("You Died") -- Put your custom message here
		end)
	end)
end)

Use the following:

Players.PlayerAdded - See Docs

Player.CharacterAdded - See Docs

Humanoid.Died - See Docs

Players:GetPlayerFromCharacter() - See Docs

Player:Kick() - See Docs

With these elements in mind, you can create the following example script:

game.Players.PlayerAdded:Connect(function(plr) -- Bind this function to when someone joins the game
    plr.CharacterAdded:Connect(function(char) -- Within that player, when it's character is added, bind this function
        char.Humanoid.Died:Connect(function() -- Then, within that character, search for the humanoid, and bind a function to when it dies
            wait(30) -- Optional, wait before kicking. Mind that the character may respawn during this period.
            plr:Kick("Custom Message") -- Kicks the player
        end)
    end)           
end)

3 comments

0

Thank you so much!!

0

For some reason it doesn't work, I placed the script inside the Boss NPC model, did I do something wrong?

0

Hey! I noticed that the last persons answer was a little different from what you wanted so I made a revised version:

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