What is the issue? Include screenshots / videos if possible!
Okay so i have a basket system in my game where u press e and it shoots the ball into the hoop
but for some reason whenever it gets close to the hoop it completely freezes for a split second then finishes https://gyazo.com/b5ec37e4a5b1aa46d96a7bdd5049490c
here is the script
script.Parent.OnServerEvent:Connect(function(player, SPos, ShootMeter,load)
local alreadyhit = false
local Hoop1 = workspace.Hoop1
local hrp = player.Character.HumanoidRootPart
local isone = false
local ball = 1
local hrp = player.Character.HumanoidRootPart
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "B-Ball" and v:FindFirstChild(player.Name) then
ball = v
ball:WaitForChild(player.Name):Destroy()
end
end
hrp.BallJoint:Destroy()
ball:SetNetworkOwner(nil)
local hrpPos = hrp.Position
local shootspawn = rps.ShootSpawn:Clone()
shootspawn.CFrame = hrp.CFrame * CFrame.new(0,3,-1)
ball.CFrame = shootspawn.CFrame
coroutine.wrap(function()
for i = 0,55 do
ball.CFrame = ball.CFrame * CFrame.fromEulerAnglesXYZ(-0.6,0,0)
task.wait()
end
end)()
local t = 1;
local g = Vector3.new(0, - workspace.Gravity, 0);
local x0 = shootspawn.CFrame * Vector3.new(0,0,0)
-- calculate the v0 needed to reach mouse.Hit.p
local v0 = (Hoop1.Position - x0 - 0.5*g*t*t)/t;
-- have the ball travel that path
ball.Velocity = v0;
ball.CFrame = CFrame.new(x0);
if (Hoop1.Position - SPos).magnitude < 1 and alreadyhit == false then
wait(1)
print("hit")
workspace.Hoop1.Swish:Play()
alreadyhit = true
script.Parent:FireClient(player)
end
if (Hoop1.Position - SPos).magnitude > 1 and (Hoop1.Position - SPos).magnitude < 1.7 and alreadyhit == false then
wait(1)
print("hit")
workspace.Hoop1.rim:Play()
alreadyhit = true
script.Parent:FireClient(player)
end
wait(0.2)
isone = true
script.Parent:FireClient(player,isone)
wait(0.2)
player.Backpack.Stuff.HasBall.Value = false
player.Backpack.Stuff.Shooting.Value = false
end)
things i already tried
changing the Network owner to server and player
turning the ball and hoop can collide off, even turned the other things in the court can collide off
even when i moved the part the pall goes to(when its shot) to a empty area of the map it still froze mid air
ive been tryna think of solutions for hours and none of them are working
This is probably the issue. If the network owner changes, the physics haults for a moment to let the closest user handle it’s physics. If you keep the network owner to the owner of the basketball, it will most likely fix the problem.
Just a consideration, but if you want to have a smoother projectile motion consider updating the CFrame via on the Client and handling the Magnitude check on the server.
Actually it is highly recommended to run projectiles on the client, this is because you are allowed to use the RenderStepped function on the client which allows you to update the projectile CFrame (Or basketball in your case) prior the frame being rendered.
local t = 1;
local x0 = ball.CFrame * Vector3.new(0,0,0)
local g = Vector3.new(0, - workspace.Gravity, 0);
local v0 = (SPos - x0 - 0.5*g*t*t)/t;
ball.Velocity = v0;
this is the line of code that moves the ball
where exactly would i use the RenderStepped function
You would have to use the :FireAllClients when the ball is fired on the server.
You would then update the ball CFrame on the client via the RenderStepped function.
You will then have to handle the hit/magnitude check on the server to prevent any exploiters bypassing the system.
This is all pseudocode, if you want a more detailed explanation check out other posts on DevForum regarding this topic.
And obviously your system works fine, so feel free to ignore this. This is just more or less a more polished and smoother way to handle projectiles if that is what you are trying to accomplish.
Oh sorry, I seemed to have misread your code above.
Normally I would update the projectile CFrame every frame for a more calculated motion and drop, but in your case you seem to use velocity so leaving on the server is fine actually.
i actually had my old system do that before but i changed it to velocity since collisions where making the ball act weird(i have a system where u can miss shots so sometimes the basket ball would go inside the rim or get stuck on the net)