New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
1

# How do I get a code to run once leader-board hits 30 units?

Edited 9 days ago

So I am making a Roblox 3rd Person shooter game and I have a leaderboard script in ServerScriptStorage which has this code

local Players = game.Players

local Template = Instance.new 'BoolValue'

Instance.new('IntValue', Template).Name = "Kills"
Instance.new('IntValue', Template).Name = "Deaths"

wait(1)
local Stats = Template:Clone()
Stats.Parent = Player
local Deaths = Stats.Deaths
Deaths.Value = Deaths.Value + 1
local Humanoid = Character:FindFirstChild "Humanoid"
if Humanoid then
Humanoid.Died:connect(function()
for i, Child in pairs(Humanoid:GetChildren()) do
if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
local Killer = Child.Value
Kills.Value = Kills.Value + 1
end
end
return -- Only one player can get a KO for killing a player. Not 2, not 3. Only one.
end
end
end)
end
end)
end)


So at the very end I am trying to get if kills = 30 then run a code.. here's my attempt

if kills == 30 then
--Runs a code for example
print("Worked")


but it didn't work and I am not a roblox engineer I am a newbie at scripting so don't just give me a code and expect me to understand it

0
you need some kind of loop that constantly checks to see if kills == 1 DarkDanny04 310 — 9d

0
Edited 8 days ago

This will be needed to be somewhere inside the player added function, and after the point that you define Kills as a variable

Kills.Changed:Connect(function(property)
if property == "Value" then
if Kills.Value == 30 then
--Code
print("Worked")
end
end
end)


What this does is it detects every time the value of Kills changes. You could use a while true do loop, but with this way, it doesnt always run which reduces server lag. If it ever changes and equals 30, then something will happen.

The reason you can't just have if statements on their own is that they only check if that statement is true when the server starts up, so they must be encased in some type of repeatable function or a loop.

I hope this helps, and if it did please accept the answer :)