Leaderstat requirement help

  1. I am trying to make a training area so if your leaderstats are less than an amount then player will be killed.

  2. I tried using a kill brick script for it so like if plr.leaderstats.Strength.Value < 50 then
    The kill brick script.

  3. I tried to look on scripting helpers and on the developer hub.

I am not asking for a whole script, but basically just a solution to make a kill brick if leaderstat is less than 50.

Thank you!

Could you post the script you tried? It sounds like you were pretty close.

4 Likes

You’d want to use a server script so as to avoid the player being able to tamper with theirs stats on the client to make it appear as if they have enough of a value.

In Pseudocode, it would probably look something like this:

-- Check if Part was touched, parameter "hit"
-- check if hit's parent contains a humanoid
-- check if hit's parent is a character of a player 
-- check if the player has the folder (or whatever instance) "leaderstats"
-- check if the player's stat value is less than a certain value
-- give punishment (set health to 0, use :LoadCharacter() to respawn, etc)
-- end
-- end
-- end
-- end
-- end

You can also use Region3 instead of a part, I found SteadyOn’s half-hour tutorial to work well for teaching how to use this, though its more complicated than using a Touched event.

Hope this helps. :slight_smile:

EDIT: In actual code it would look something like below.

local Players = game:GetService("Players")
local Part = script.Parent
Part.Touched:connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if not humanoid or humanoid.Health == 0 then return end -- already dead
    local Player = Players:GetPlayerFromCharacter(hit.Parent)
    if not Player then return end
    local leaderstats = Player:FindFirstChild("leaderstats")
    if not leaderstats then return end
    if leaderstats.Strength.Value < 50 then
        Player:LoadCharacter() -- Respawns, use humanoid.Health = 0 to kill
    end
end)

“if not {condition} then return end” is just my way of reducing the number of ends and indents at the end of the code and mainly for readability over efficiency. Using
“if {condition} then --code end” is fine.

1 Like

Hello Lightlimn, I am going to show the script soon, I don’t have it right here. I’ll notify you, thanks!