I am very new to scripting and not really sure what to do, I'm making a game. I've already tried to use two tutorials but it was unsuccessful.
The attempt that I had tried was when Roblox went down for a little bit, so I lost my progress.
Here is a stable script! (Insert as a ServerScript in StarterCharactersScripts)
local humanoid = script.Parent.Humanoid local player = script.Parent:GetPlayerFromCharacter() humanoid.Died:Connect(function() player:Kick("You died!") end)
Ok, now lets run over the code.
Line 1 - 2 - Referencing the humanoid and the player.
local humanoid = script.Parent.Humanoid -- Get's humanoid. (No need for waitforchild) local player = script.Parent:GetPlayerFromCharacter() -- Gets the player.
Line 4 - 6 --- Connects player death and kicks.
humanoid.Died:Connect(function() ---- Connects a function when the player dies player:Kick("You died!") --- Kicks player with the message "You died!" end) --- Ends the function duh.
Enjoy the script :) Tell me if there are any errors.
I'll help you.
We can add a script to the StarterCharacterScripts (i'm really messy, but idk how it's called, i think it's in starterplayers) and add these lines of code:
This is my way of doing it: First, let's find the humanoid of the character
local humanoid = script.Parent:WaitForChild("Humanoid") -- We'll search for the humanoid if it exists.
Good, now that we found the humanoid, we can run a loopedy-loop untill a humanoid hits 0 hp. You can use a while wait() do but i think it's quite unnecessary. I'd rather run a Repeat.
repeat wait() until humanoid.Health <= 0 -- This line of code will repeat a wait() loop until the humanoid's health is 0 (or under in some cases.)
Now, you can add a optional wait(seconds) if you want the person to stay for seconds before being kicked, but you can also just remove it.
We have to find the Player now. We can use game.Players:GetPlayerFromCharacter(). The character must be defined inside the brackets of it. aka (script.Parent)
After we found the player, we can run a player:Kick("reason here") on them.
Hope i explained something and helped you.