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.
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.