I am making a simulator game called Shard Clicker. I am trying to make a hack prevention script so when the localplayer reaches 1000000 value in Crystals that they will be kicked. Here is the script.
plr = game.Players.LocalPlayer stat = plr.leaderstats.Crystals if stat.Value == 1000000 then plr:Kick() end
while wait(5) do for i,v in pairs(game.Players:GetPlayers()) do if v:FindFirstChild("leaderstats") then if v.leaderstats:FindFirstChild("Crystals") then if v.leaderstats.Crystals.Value >= 100000 then v:Kick("You Have Too Much Gems") end end end end end
i hope it worked, if it got any errors then i'm sorry, be sure to comment so i can help you
The best way is to check the value whenever it changes. This can be done by having a function fire on the Changed event of your leaderstat, which you can connect when the player enters the game. This means that this script would have to be in your Workspace.
game.Players.PlayerEntered:connect(function(player) player:WaitForChild("leaderstats") player.leaderstats.Crystals.Changed:connect(function(value) if (value >= 1000000) then player:Kick() end end) end)
Okay, first,
Is the script a localscript? If not, that's your problem.
If not that,
player = game.Players.LocalPlayer repeat wait() until player.leaderstats.Crystals -- Waits for the leaderstats to load in local stat -- Provides a wait for later wait() stat = player.leaderstats.Crystals if stat.Value >= 1000000 then player:Kick("stop hacking you loser") -- Removable end
Put this in a localscript inside StarterGear.