edit: for some reason the ball is anchored on the client when it gets network ownership
What do you want to achieve? to make the ball bounce and not freeze in the air
What is the issue? it freezes in the air (when network ownership is on the client)
What solutions have you tried so far? nothing worked
it worked before but now it just doesnt
this the script where it gives netowrk ownership (i took it from some random grenade video)
local tool = script.Parent.Parent
local players = game:GetService("Players")
local cooldown = 0.2
local coolingDown = false
local char
local player
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remote2 = tool.Connection
local testremote = ReplicatedStorage.ballc
--if tool.Parent.Name == "Backpack" then
--end
tool.Equipped:Connect(function()
char = tool.Parent
script.Parent.Character.Value = char
end)
tool.Unequipped:Connect(function()
char = nil
end)
local mouseCF
tool.Handle.MouseInfoRE.OnServerEvent:Connect(function(plr, mouseHit)
player = plr
mouseCF = mouseHit
end)
tool.Activated:Connect(function()
local clone = tool.Handle:Clone()
clone.GrenadeHandler:Destroy()
clone.MouseInfo:Destroy()
clone.MouseInfoRE:Destroy()
clone.CanCollide = true
clone.CanTouch = true
clone.Trail.Enabled = true; clone.limit.Enabled = true
print("limit enabled")
local bv = Instance.new("BodyVelocity")
bv.Velocity = mouseCF.LookVector * 100
bv.Parent = clone
clone.Parent = workspace
--print(clone:CanSetNetworkOwnership())
print(player)
clone:SetNetworkOwner(player)
--clone:ApplyImpulse(Vector3.new(0,0,0.01))
--task.wait(0.1)
remote2:FireClient(player, clone)
task.delay(60,function()
clone:SetNetworkOwner(nil)
task.wait(.1)
clone:Destroy()
end)
wait(.1)
bv:Destroy()
end)
and this is the client script
--local cap = false
local connection:RBXScriptConnection
print("i exist")
local remote = script.Parent:WaitForChild("Connection")
remote.OnClientEvent:Connect(function(ball:BasePart)
print("ball is active (probably)")
ball:ApplyImpulse(Vector3.new(0,0,0.001))
print("impulse")
ball.Touched:Connect(function(object)
print("touch")
if object:IsA("Part") then
print("check")
task.wait(0.01)
ball:ApplyImpulse(ball.AssemblyLinearVelocity * 0.3)
if ball:FindFirstChild("Sound") ~= nil then
ball.Sound:Play()
end
end
end)
task.wait()
print("connection")
connection = game:GetService("RunService").Stepped:Connect(function(time: number, deltaTime: number)
if ball then
local x2 = math.clamp(ball.AssemblyLinearVelocity.X,-160,160)
local y2 = math.clamp(ball.AssemblyLinearVelocity.Y,-160,160)
local z2 = math.clamp(ball.AssemblyLinearVelocity.Z,-160,160)
ball.AssemblyLinearVelocity = Vector3.new(x2,y2,z2)
task.wait(.3)
else
connection:Disconnect()
end
end)
end)
the scripts probably have a trillion bugs and memory leaks but this is admin only so i didnt bother to fix
i should just give the entire ball model but idk how to upload rbxm (and if i can)
ok i can attach the file so this is the ball thing (it randomly fixes itself and bugs itself at random times so its just roblox being freaky ig i still want a way to make it bug itself less) scp018 .rbxm (10.0 KB)
There is nothing you can do about that. It’s even mentioned in the documentation, how things freeze for a second when the ownership changes. You could try using RunService + some lerping to smooth it out, but that seems a bit off, I don’t think it would work.
You can set the network ownership before parenting to the workspace, though any action done on server will always freeze due to latency (it may not be visible in studio) as your machine is the server so you don’t have like kilometres of distance to account for, but by setting network ownership to the person throwing the ball it also causes security issues as what if on their side they deleted a wall and now it allows them to throw the ball through a solid wall?
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local RemoteEvent = tool:WaitForChild("RemoteEvent")
local connection = nil
tool.Activated:Connect(function()
RemoteEvent:FireServer(mouse.Hit.Position)
end)
RemoteEvent.OnClientEvent:Connect(function(ball)
ball:ApplyImpulse(Vector3.new(0, 0, 0.001))
ball.Touched:Connect(function(hit)
ball:ApplyImpulse(ball.AssemblyLinearVelocity * 0.3)
local sound = ball:FindFirstChild("Sound")
if sound then
sound:Play()
end
end)
connection = RunService.Stepped:Connect(function()
if ball then
local velocity = ball.AssemblyLinearVelocity
local x2 = math.clamp(velocity.X, -160, 160)
local y2 = math.clamp(velocity.Y, -160, 160)
local z2 = math.clamp(velocity.Z, -160, 160)
ball.AssemblyLinearVelocity = Vector3.new(x2, y2, z2)
else
connection:Disconnect()
end
end)
end)
Server:
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local tool = script.Parent
local Handle = tool:WaitForChild("Handle")
local RemoteEvent = tool:WaitForChild("RemoteEvent")
local connection = nil
local function HandleBall(ball)
ball.Touched:Connect(function(hit)
ball:ApplyImpulse(ball.AssemblyLinearVelocity * 0.3)
local sound = ball:FindFirstChild("Sound")
if sound then
sound:Play()
end
end)
connection = RunService.Stepped:Connect(function()
if ball then
local velocity = ball.AssemblyLinearVelocity
local x2 = math.clamp(velocity.X, -160, 160)
local y2 = math.clamp(velocity.Y, -160, 160)
local z2 = math.clamp(velocity.Z, -160, 160)
ball.AssemblyLinearVelocity = Vector3.new(x2, y2, z2)
else
connection:Disconnect()
end
end)
end
RemoteEvent.OnServerEvent:Connect(function(player, mousePos)
local clone = Handle:Clone()
clone.GrenadeHandler:Destroy()
clone.MouseInfo:Destroy()
clone.MouseInfoRE:Destroy()
clone.CanCollide = true
clone.CanTouch = true
clone.Trail.Enabled = true
clone.limit.Enabled = true
clone.Parent = workspace
clone:SetNetworkOwner(player)
local direction = (mousePos - clone.Position).Unit
clone.AssemblyLinearVelocity = direction * 100
HandleBall(clone)
task.delay(60, function()
if clone then
clone:SetNetworkOwner(nil)
game:GetService("Debris"):AddItem(clone, 0.1)
end
end)
end)