Hi so ive got this script where it checks if your in the range in the magnitude but how can i make it so it keeps on checking until someone gets to the magnitude
Heres the code:
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Equiped = false
local character = Player.Character
if not character or not character.Parent then
character = Player.CharacterAdded:wait()
end
local Enabled = false
local Power = 10
local Holding = false
Mouse.Button1Down:Connect(function()
Power = 10
Holding = true
while Holding == true do
wait()
print(Power)
Power += 3.42
if Power >= 80 then
Power = 80
end
end
end)
Mouse.Button1Up:Connect(function()
Holding = false
if (character["Right Leg"].Position - game.Workspace.Ball.Position).Magnitude <= 2 then
game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent"):FireServer(game.Workspace.Ball)
local F = Instance.new("BodyVelocity") -- Creates a Force
F.P = 9
F.Parent = game.Workspace.Ball -- Makes the force act on the ball
F.Name = script.Name -- Make the force's name the script's name
F.velocity = character.HumanoidRootPart.CFrame.lookVector * Power + Vector3.new(0,Power - 40,0) -- The force is where the Right Leg is looking (so if your right leg was looking towards the goal then the ball would go to the goal) and its given a certain value to go against (the higher the number, the faster the ball would go)
F.maxForce = Vector3.new(math.huge,math.huge,math.huge) -- The maximum force it's allowed to give the ball
game.Debris:AddItem(F,0.3) -- This destroys the Force within 0.3 seconds without stopping the code so it doesn't keep the ball moving
end
end
end)
HumanoidRootPart:GetPropertySignalChanged(âPositionâ):Connect(function()
-- check distance
if (HumanoidRootPart.Position - workspace.Ball.Position).Magnitude < integer then
-- code
end
end)
P.S. this fires every time the player moves
Dunno if Iâd recommend this exact method for performance