Help with soccer ball power

Hi, so I am trying to make a soccer game but I have a problem. There is too little power on the ball when I click it, even if I hold down for long enough:

The script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")

local Modules = ReplicatedStorage:WaitForChild("Modules")
local BridgeNet = require(Modules:WaitForChild("BridgeNet"))
local RemoteEvent = BridgeNet.CreateBridge("Physics")

RemoteEvent:Connect(function(Player, Balls, Duration, Position, LookVector)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	local Torso = Character:WaitForChild("Torso")
	local Head = Character:WaitForChild("Head")
	local Distance = Head.Position.Magnitude - Balls.Position.Magnitude
	if Distance > 1 then return end
	if not Torso:FindFirstChild("BallWeld") then return end
	local Force = math.floor(Duration * 25)--250) 
	print(Force)


	local BodyForce = Instance.new("BodyForce") 
	BodyForce.Force = Torso.CFrame.LookVector * 1500 * Duration + Vector3.new(100,3000+Duration,100)
	BodyForce.Name = Player.Name
	BodyForce.Parent = Balls 
	Debris:AddItem(BodyForce , 0.025)

	for _, v in pairs(Torso:GetDescendants()) do
		if v:IsA("Weld") and v.Name == "BallWeld" then
			v:Destroy()
		end
	end 
end)

(there is also a client script you can ask for that if needed)

Any help would be appreciated, thanks!

1 Like

Heres one thing - Dont use body force since its deprecated. You can use vector force or linear force. Try tinkering with that instead.

2 Likes

Thanks, I will try that and see how it goes.

It gives me this error here:

Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")

local Modules = ReplicatedStorage:WaitForChild("Modules")
local BridgeNet = require(Modules:WaitForChild("BridgeNet"))
local RemoteEvent = BridgeNet.CreateBridge("Physics")

RemoteEvent:Connect(function(Player, Balls, Duration, Position, LookVector)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	local Torso = Character:WaitForChild("Torso")
	local Head = Character:WaitForChild("Head")
	local Distance = Head.Position.Magnitude - Balls.Position.Magnitude
	if Distance > 1 then return end
	if not Torso:FindFirstChild("BallWeld") then return end

	local Force = math.floor(Duration * 500) 

	local VectorForce = Instance.new("VectorForce")
	VectorForce.Force = HumanoidRootPart.CFrame.LookVector * Force
	VectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
	VectorForce.Attachment0 = HumanoidRootPart.RootAttachment
	VectorForce.Attachment1 = Balls
	VectorForce.Parent = Balls

	Debris:AddItem(VectorForce, 0.5)

	for _, v in pairs(Torso:GetDescendants()) do
		if v:IsA("Weld") and v.Name == "BallWeld" then
			v:Destroy()
		end
	end
end)
1 Like

Make sure the balls variable actually is a instance. I don’t know much. If you want to give your ServerBridge code for us to review further, then that’s fine.

1 Like

Make sure the Balls thing is an attachment, Have you tried to do Type Checking?

ok i fixed it i accidently put Balls instead of Balls.Attachment, but the ball still has no power at all

try tinkering with the number values. Have you yet? I’m clueless, sorry.

Yes, and now this happens:

1 Like

Probably because its dragging You and the ball, since you are using vector force. Try implementing Linearforce or Lineforce instead.

The same thing happened when using LinearVelocity

This is the client script (only a bit):

UserInputService.InputEnded:Connect(function(Input, GameProcessed)
	if Input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
	if not Torso:FindFirstChild("BallWeld") then return end
	if GameProcessed then return end

	MouseDown = false
	local Duration = tick() - StartedDown

	if Duration >= 0.75 then
		Duration = 0.75
	end

	local Power = Duration / 0.75
	RemoteEvent:Fire(Balls, Power)
	setPowerBarSize(0)
	TackleAnimation:Stop(0.3)
	KickAnimation:Stop(0.3)
	task.wait(Cooldown)
	resetPowerBar()
end)
1 Like

ok, it has seemed like I have solved the power situation, just by adjusting this script

UserInputService.InputEnded:Connect(function(Input, GameProcessed)
	if Input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
	if not Torso:FindFirstChild("BallWeld") then return end
	if GameProcessed then return end

	MouseDown = false
	local Duration = tick() - StartedDown

	if Duration >= 0.75 then
		Duration = 0.75
	end

	local Power = Duration / 0.75
	RemoteEvent:Fire(Balls, Power)
	setPowerBarSize(0)
	TackleAnimation:Stop(0.3)
	KickAnimation:Stop(0.3)
	task.wait(Cooldown)
	resetPowerBar()
end)

But i want it so the higher the power, the higher the ball should go

1 Like

ok… I have figured out a solution but sometimes when I click it doesn’t work:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")

local Modules = ReplicatedStorage:WaitForChild("Modules")
local BridgeNet = require(Modules:WaitForChild("BridgeNet"))
local RemoteEvent = BridgeNet.CreateBridge("Physics")

RemoteEvent:Connect(function(Player, Balls, Duration, Position, LookVector)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
	local Torso = Character:WaitForChild("Torso")
	local Head = Character:WaitForChild("Head")
	local Distance = Head.Position.Magnitude - Balls.Position.Magnitude

	if Distance > 1 then return end
	if not Torso:FindFirstChild("BallWeld") then return end

	local Force = math.floor(Duration * 25)

	local VectorForce = Instance.new("VectorForce")
	VectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
	VectorForce.Force = Vector3.new(0, Force*100, 0)
	VectorForce.ApplyAtCenterOfMass = true
	VectorForce.Parent = Balls

	local BodyVelocity = Instance.new("BodyVelocity")
	BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	BodyVelocity.Velocity = Torso.CFrame.LookVector * (Force * 2) + Vector3.new(0, Force * 2.5, 0)
	BodyVelocity.P = 10000
	BodyVelocity.Parent = Balls

	local GravityScale = Instance.new("NumberValue")
	GravityScale.Name = "GravityScale"
	GravityScale.Value = 2
	GravityScale.Parent = Balls

	Debris:AddItem(VectorForce, 0.025)
	Debris:AddItem(BodyVelocity, 0.025)
	Debris:AddItem(GravityScale, 0.025)

	for _, v in pairs(Torso:GetDescendants()) do
		if v:IsA("Weld") and v.Name == "BallWeld" then
			v:Destroy()
		end
	end
end)
1 Like

an easier way to tackle this instead of using so many different methods to implement velocity into the ball is to initialize its velocity using a BodyVelocity and at the same time set the ball’s AssemblyLinearVelocity to the same thing, then quickly deleting the BodyVelocity with practically a frame or two of it being added. as for your current code not working sometimes I can see a couple things probably being an issue however im not too certain as i don’t know how the ball fully works.

best solution is to print a bunch of variables and see if its the shooting code not working or if theres something else at play.

1 Like

Try turning the debris up, bodyforces apply the force gradually instead of applying it instantly like body velocities.