Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Kill player if they have certain value?

Asked by 3 years ago

I want to kill the player if they make contact with an invisible box if they have a value over 1. The value is located at player.leaderstats.Stage.Value . I tried to look everywhere for things related to this, and I couldn't find anything. I'm not a very good scripter, so if you could, please explain what I could do to make this happen.

1 answer

Log in to vote
3
Answered by 3 years ago

Hello, one way to do this would be to connect .Touched to the part, .Touched gives a parameter for the part that touched the box, we can check if the part is a rig by checking if a humanoid exists in the character, if there is a humanoid, we know it's a rig, but to check and get the player, we can use GetPlayerFromCharacter to get it, then we just get the stage value and check if it's greater than 1, if it is, set the humanoid health to 0

01local players = game:GetService("Players") -- This will be useful, and it is good practice to use GetService
02local part = script.Parent -- Assuming this script is inside your invisible box
03local valueThatKillsYouLol = 1 -- you can just change the name if you want, this is optional if you want more than 1 invisible box, we are gonna check if the stage value is greater than this (e.g 1)
04 
05part.Touched:Connect(function(hit)
06    local humanoid = hit.Parent:FindFirstChild("Humanoid") -- We use FindFirstChild because it returns nil if the child is not found, because we don't know if the part that touched is a character
07    if (humanoid) then
08        -- If it's a character
09        local player = players:GetPlayerFromCharacter(script.Parent) -- Getting the player
10        if (not player) then
11            -- If the character is a dummy or an npc
12            return -- don't go further than this line, this return will stop the code
13        end
14        local leaderstats = player:FindFirstChild("leaderstats")
15        if (leaderstats) then -- if the player's leaderstats are there and loaded
View all 25 lines...
0
What is the GetService use? GiantAgeman 0 — 3y
Ad

Answer this question