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

Why will the player not be kicked when they reach a value in a leaderstat?

Asked by
Jacksez 15
6 years ago

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

3 answers

Log in to vote
0
Answered by 6 years ago
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

0
And put this in normal script marijus06 68 — 6y
Ad
Log in to vote
0
Answered by
mraznboy1 194
6 years ago

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)
Log in to vote
-1
Answered by 6 years ago
Edited 6 years ago

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.

0
"stop hacking you loser" lol. Downvoted. F4ULT1NTH3D4T4 226 — 6y
0
well thats pretty mean FireyMcBlox 134 — 6y

Answer this question