Hi.
So I am making a ROBLOX “Soccer” game and there is this slide tackle script that is overpowered, and I want to make it so the player can only slide tackle if they are within a close range of the ball.
The current function I am using:
function CloseEnoughToABall()
--[[
unfortunately you dont use
collectionservice to track the balls or anything in general, so i have to use
more inefficient method.
--]]
local Character = Player.Character
if not Character then return end
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
if not HumanoidRootPart then return end
local CharacterPosition = HumanoidRootPart.Position
-- DFC stands for distance from character
local ClosestBall
local ClosestBallDFC
local Children = game:GetService("Workspace"):GetChildren()
for _, Child in pairs(Children) do
if Child.Name == "Eve" then
local DescendantPosition = Child.Position
if ClosestBall and ClosestBallDFC then
local DistanceFromCharacter = (CharacterPosition - DescendantPosition).Magnitude
if DistanceFromCharacter < ClosestBallDFC then
ClosestBall = Child
ClosestBallDFC = DistanceFromCharacter
end
else
local DistanceFromCharacter = (CharacterPosition - DescendantPosition).Magnitude
ClosestBall = Child
ClosestBallDFC = DistanceFromCharacter
end
end
end
if ClosestBallDFC then
if ClosestBallDFC < Range then
return true
else
return false
end
else
return false
end
end
Mouse.Button1Down:connect(function()
if not CloseEnoughToABall() then return end
if Equipped == false then return end
if TM.GetDebounce() then return end
-- script below this, works so i decided not to paste it in
end)
Any help would be appreciated, thanks!