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

Why is the roblox engine calling a function in if statement?

So, I am trying to do an anti cheat system and I've tried this script but the problem is that its calling a function in an if statement

local player = game.Players.LocalPlayer
local speed = 10
local mouse = player:GetMouse()
local isFlying = false


function GetMassRecursive(p)
	local mass = 0
	for i,v in pairs(p:GetChildren())do
		if #v:GetChildren() > 0 then
			mass = mass + GetMassRecursive(v)
		end
		if v:IsA("Part") then
			print(v.Name)
			mass = mass + v:GetMass()
		end
	end
	return mass
end


function Flying(p)
	    	speed = 10
			local f = Instance.new("BodyForce")
			f.Name = "Anti-Grav"
			f.Force = Vector3.new(0,196.2,0) * (GetMassRecursive(player.Character))
			f.Parent = player.Character.Torso
			local v = Instance.new("BodyVelocity")
			v.Velocity = (mouse.Hit.p - player.Character.Torso.Position).unit * 10
			v.P = 100
			v.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			v.Name = "FlyingVelocity"
			v.Parent = player.Character.Torso
			player.Character.Humanoid.PlatformStand = true
			isFlying = true
end


function NotFlying(p)
	speed = 0
	wait()
	player.Character.Torso["Anti-Grav"]:Destroy()
	player.Character.Torso["FlyingVelocity"]:Destroy()
	player.Character.Humanoid.PlatformStand = false
	isFlying = false
end

function KickFly()
	player:Kick("Fly hacking...")
end

while wait(1)do
    if Flying() then
	NotFlying()
	isFlying = true
    end 
end
	if isFlying  == true then
		KickFly()
	end

sorry if the script is too long, but the problem is at line 53

4 comments

0

wait() should NOT be the loop's condition.

0

Ok, sorry. It's just for testing purposes.

0

then don't call the function at line 53 lol

0

But, I want to check if the player is doing the function, how would I do that?

1 answer

✓ Accepted answer

Considering you have a BodyVelocity, what you can do is search for a BodyVelocity in the torso using the FindFirstChild method. This is a great substitute which won't call the function. You may be wondering, why don't we just return v instead? Well, returning a value in a function would also mean that we would have to call it in the variable we assign to; therefore searching for the velocity with FindFirstChild will be more beneficial.

local player = game.Players.LocalPlayer
local speed = 10
local mouse = player:GetMouse()
local isFlying = false
--Add some new variables
local char = player.CharacterAdded:Wait()
local torso = char:WaitForChild("Torso")

--Skipping Straight to Line 53, the if statement.

while wait(1) do
	if torso:FindFirstChild("FlyingVelocity") then
		NotFlying()
		isFlying = true
		end
	end
   	 if isFlying  == true then
           KickFly()
         end

--That would do it, to finish it off.

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