Repository navigation
Blade ball #15
Description
-- BladeBallServer
-- Coloque em ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local remote = ReplicatedStorage:FindFirstChild("ParryRequest")
if not remote then
remote = Instance.new("RemoteEvent")
remote.Name = "ParryRequest"
remote.Parent = ReplicatedStorage
end
local ball = workspace:FindFirstChild("BladeBall")
if not ball then
ball = Instance.new("Part")
ball.Name = "BladeBall"
ball.Shape = Enum.PartType.Ball
ball.Size = Vector3.new(2, 2, 2)
ball.Material = Enum.Material.Neon
ball.Color = Color3.fromRGB(255, 55, 75)
ball.Position = Vector3.new(0, 8, 0)
ball.Parent = workspace
end
ball.Anchored = false
ball.CanCollide = false
ball:SetNetworkOwner(nil)
local SPEED = 65
local PARRY_RANGE = 13
local COOLDOWN = 0.65
local lastParry = {}
local targetPlayer = nil
local function getRoot(player)
local character = player.Character
return character and character:FindFirstChild("HumanoidRootPart")
end
local function getNearestPlayer(origin, excludedPlayer)
local nearest, distance = nil, math.huge
for _, player in ipairs(Players:GetPlayers()) do
if player ~= excludedPlayer then
local root = getRoot(player)
local humanoid = player.Character
and player.Character:FindFirstChildOfClass("Humanoid")
if root and humanoid and humanoid.Health > 0 then
local d = (root.Position - origin).Magnitude
if d < distance then
distance = d
nearest = player
end
end
end
end
return nearest
end
local function aimAtTarget()
if not targetPlayer or not getRoot(targetPlayer) then
targetPlayer = getNearestPlayer(ball.Position, nil)
end
local root = targetPlayer and getRoot(targetPlayer)
if root then
local direction = root.Position - ball.Position
if direction.Magnitude > 0 then
ball.AssemblyLinearVelocity = direction.Unit * SPEED
end
end
end
remote.OnServerEvent:Connect(function(player)
local now = os.clock()
if now - (lastParry[player] or 0) < COOLDOWN then
return
end
local root = getRoot(player)
if not root then return end
if (root.Position - ball.Position).Magnitude > PARRY_RANGE then
return
end
lastParry[player] = now
-- Rebate a bola em direção a outro jogador.
targetPlayer = getNearestPlayer(ball.Position, player)
local direction
local targetRoot = targetPlayer and getRoot(targetPlayer)
if targetRoot then
direction = targetRoot.Position - ball.Position
else
direction = root.CFrame.LookVector
end
if direction.Magnitude > 0 then
ball.AssemblyLinearVelocity = direction.Unit * SPEED
end
end)
local timer = 0
RunService.Heartbeat:Connect(function(dt)
timer += dt
if timer >= 0.25 then
timer = 0
aimAtTarget()
end
end)
Players.PlayerRemoving:Connect(function(player)
lastParry[player] = nil
if targetPlayer == player then
targetPlayer = nil
end
end)
Activity