Hello, I am currently recreating blade ball but editing into more like a dodgeball game.
I am adding features like deflecting the ball with other ball, catching the ball (risky) etc…
I am currently scripting throwing the ball after having caught it which consists of holding a button for 5 seconds to charge the force of throwing the ball, at the end you stop holding the key and you throw the ball. I am having trouble making the ball find the nearest player and follow it. Here is my script.
I have done finding the nearest player but I’m struggling on sending the ball to them? How would I?
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local DebrisService = game:GetService("Debris")
local StarterGuiService = game:GetService("StarterGui")
local PathFindingService = game:GetService("PathfindingService")
local ThrowBallEvent = game.StarterPack["Throw Ball"].ThrowBallEvent
local Speed = ReplicatedStorageService.Value.Value
local Ball = game.Workspace.Ball
ThrowBallEvent.OnServerEvent:Connect(function(Player, Thrown)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
if Thrown then
else
local Animation = Humanoid:LoadAnimation(script["Throw Ball"])
Animation:Play()
local Part = Instance.new("Part")
Part.Parent = workspace
Part.Transparency = .5
Part.CFrame = Root.CFrame
Part.Size = Vector3.new(2048, 2048, 2048)
Part.Anchored = true
Part.CanCollide = false
Part.Touched:Connect(function(hit)
print(hit.Parent)
if hit.Parent == Character then return end
if hit.Parent:FindFirstChild("Humanoid") then
local Distances = {}
for i, player in pairs(game.Players) do
local character = Player.Character
local hrp = character.Primarypart
local distance = math.abs((hrp.position - Ball.position).Magnitude)
Distances[i] = {["Player"] = player, ["Distance"] = distance}
end
local smallestplrdist
for i, v in pairs(Distances) do
if i-1 < 1 then return end
if v.Distance < Distances[i-1].Distance then
smallestplrdist = v.Player
v.Player = hit.Parent
end
end
end
end)
end
end)```