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