Server Script 1
local Services = {
Players = game:GetService("Players"),
Debris = game:GetService("Debris")
}
local Ball = script.Parent
local KickSound = Ball:WaitForChild("Kick")
local velocityLength = 0.4 --// this number should not be < 0.4
bounce = false
Ball.Touched:Connect(function(t)
local char = t.Parent
if not char then
return
end
Ball:SetNetworkOwner(nil)
local plr = Services.Players:GetPlayerFromCharacter(char)
local Humanoid = char:FindFirstChildOfClass("Humanoid")
local Root = char:FindFirstChild("HumanoidRootPart")
if not plr or not Humanoid or Humanoid.Health <= 0 or not Root then
return
end
local makeNewVelocity = false
local ballVelocity = Ball:FindFirstChild("BallVelocity")
if ballVelocity then
if ballVelocity.LastKicked.Value ~= plr.Name then
ballVelocity:Destroy() --// destroy other player's velocity to create a new one
makeNewVelocity = true
else
warn(plr.Name.." kicked the ball while they still had a body velocity active.")
end
else
makeNewVelocity = true
end
if makeNewVelocity and bounce == false then
bounce = true
-- local Direction = CFrame.lookAt(Root.Position, Root.Position).LookVector
local Direction = Root.CFrame.LookVector
if Direction.Magnitude < 0.001 then
return
end
local Velocity = Instance.new("BodyVelocity", Ball)
Velocity.Name = "BallVelocity"
Velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
local lastKicked = Instance.new("StringValue", Velocity)
lastKicked.Name = "LastKicked"
lastKicked.Value = plr.Name
local Kick_Force = Humanoid.WalkSpeed
Velocity.Velocity = (Direction.Unit * Kick_Force * 1.7) + Vector3.new(0, Kick_Force * .5, 0)
Services.Debris:AddItem(Velocity, velocityLength)
KickSound:Play()
task.wait(1) --// Kick CoolDown
bounce = false
if Ball:GetAttribute('LastTouch') ~= nil then
if Ball:GetAttribute('LastTouch') ~= plr.Name then
local st = Ball:GetAttribute('LastTouch')
Ball:SetAttribute('LastTouch', plr.Name)
Ball:SetAttribute('SecondTouch', st)
else
end
else
Ball:SetAttribute('LastTouch', plr.Name)
end
local TeamName = plr:GetAttribute('TeamName')
if game.ServerStorage.GameFolder.Standings:FindFirstChild(TeamName) ~= nil and game.ServerStorage.GameFolder.Standings:FindFirstChild(TeamName):GetAttribute("Touches") ~= nil then
game.ServerStorage.GameFolder.Standings:FindFirstChild(TeamName):SetAttribute('Touches', game.ServerStorage.GameFolder.Standings:FindFirstChild(TeamName):GetAttribute('Touches') + 1)
end
end
end)