Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my anti-KO exploit not work when I clone it?

I made a script that checks you KOs to make sure people are not exploiting them. It works when I do:

wait(3)

script.Parent = game.Players.xXGokyXx

if true then

Player = script.Parent.Name

Kills = 0

PrevKills = 0

  

function onChanged()

Kills = game.Players[Player].leaderstats.KOs.Value

print(Kills-PrevKills)

if Kills - PrevKills > 3 then

game.Players[Player]:Kick("Kicked for exploit killing")

else

PrevKills = Kills

end

end

game.Players[Player].leaderstats.KOs.Changed:Connect(onChanged)

end

But then this does not work:

wait(1)

local Players = game:GetService("Players")

  

if script.Parent.Name == "ServerScriptService" then

Players.PlayerAdded:Connect(function(player)

local ak = script:Clone()

ak.Parent = game.Players[player.Name]

end)

end

  

if script.Parent.Name == "Players" then

Player = script.Parent.Name

Kills = 0

PrevKills = 0

  

function onChanged()

Kills = game.Players[Player].leaderstats.KOs.Value

print(Kills-PrevKills)

if Kills - PrevKills > 3 then

game.Players[Player]:Kick("Kicked for exploit killing")

else

PrevKills = Kills

end

end

game.Players[Player].leaderstats.KOs.Changed:Connect(onChanged)

end

  

local Players = game:GetService("Players")

Both are in ServerScriptService and neither return errors. I tried some other stuff but nothing else worked. How would I make it clone the script and still work? Both scripts go to the right place as well.

1 answer

I'm happy to help! A few things you should learn from this.

The Roblox event

Players.PlayerAdded:Connect(function(player)

already gives you the players location. Say I join a game, my username will be Conmmander. the player is equal to game.Players["Conmmander"]

That being said, you can make this line into

//Old
ak.Parent = game.Players[player.Name]
//New
ak.Parent = player

Something else you can fix is to remove

wait(1)

It doesn't do anything, and won't contribute to your code, as the only top variable is the Players service. Your performance should be better without it.

The primary thing wrong with your script is that you attempt to check the name of the scripts location. It will come up as false since you're looking at the wrong area. You need to add another

.Parent

Something else I noticed was you did not make all your variables start with

local

This is very important. We are lucky that lua won't punish us for not making our variables start with it, but it is good practice. If you choose other languages to learn like JavaScript, you'll find that they have 3 different variable types. Simply not defining it, doesn't work anymore.

I've included a copy of the script, with all the errors fixed, and things should hopefully work. Since we don't know exactly how you're using it, you may have to make some changes based on your environment.

Enjoy!

local Players = game:GetService("Players")

if script.Parent.Name == "ServerScriptService" then
Players.PlayerAdded:Connect(function(player)
local ak = script:Clone()

ak.Parent = player

end)

end

if script.Parent.Parent.Name == "Players" then
 local Player = script.Parent.Name

Kills = 0

PrevKills = 0

function onChanged()

Kills = game.Players[Player].leaderstats.KOs.Value

print(Kills-PrevKills)

if Kills - PrevKills > 3 then

game.Players[Player]:Kick("Kicked for exploit killing")

else

PrevKills = Kills

end

end

game.Players[Player].leaderstats.KOs.Changed:Connect(onChanged)

end

  

local Players = game:GetService("Players")

7 comments

0

I never said it was required. I recommended that he do it.

0

Heh. You aren't using local functions. Great job.

0

And I mean that with extreme irony.

0

You should be using locales always. Your comment is cancer so im deleting it

0

Thanks @incapaxx

0

You could has just said the parent thing was it but thanks for all the other stuff I guess.

0

Also it still doesn't work @Conmmander

This discussion is preserved as it was. New answers, comments, and votes are closed.