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

how to use return properly? I'm trying to make an anticheat but it doesn't work.

local Character = game.Players.LocalPlayer.Character

local CharPos = Character.HumanoidRootPart.Position.X

for i = 1,10 do
	if CharPos > CharPos * 2 == true and i == 10 then
		game.Players.LocalPlayer:Kick("cool")
	end
	print(CharPos)
	if  CharPos > CharPos * 2 == not true and i == 10 then
		return i
	end
end

i'm pretty sure im doing something here completely wrong but what im trying to do is have a timer of 1 to 10 and when it reaches 10 it checks if the Character position is bigger then what it was before and if it is then kick the player and if it isnt than restart the count its kind of an anticheat but ik its really bad but why does it not work?

6 comments

0

Theres no wait in the loop so all the checks would be almost instant, and you should just do CharPos > CharPos*2

0

What exactly do you mean by "bigger"?

0

if CharPos > CharPos * 2, if the position is X 2 bigger than what it was.

0

add a wait in the function so checks would not be done in one fraction of a second.

0

Do you mean they moved further???!! Be more descriptive.

0

"return" would not work here, but "break" would.

1 answer

✓ Accepted answer

Hey brodski40, good question!

If your goal is to try and check the position and see if the position is greater than when the timer started, I will show you how to do such that.

-- Local Script
local Players = game:GetService("Players")

local player = Players.LocalPlayer

local function runTimer()
	local char = player.Character
	if (not char) then return end 
	
	local startPos = char:GetPrimaryPartCFrame().p
	local startDist = (startPos - Vector3.new(0, 0, 0)).Magnitude
		
	delay(10, function()
		local currentPos = char:GetPrimaryPartCFrame().p
		local currentDist = (currentPos - Vector3.new(0, 0, 0)).Magnitude
		
		if (currentDist > startDist) then 
			player:Kick()
		end 
	end)
end

Hope this helps!

1 comment

0

Looks good although I don't completely understand it I'll try to learn from it thanks!

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