Hey Roblox Devs! I’m currently having tons of trouble with syncing player velocity to the server. I have been working on it for so freaking long at it’s making me loose my mind haha. So far I’ve tried using RemoteFunctions (have no idea how those work so couldn’t do it with those) and RemoteEvents (too much network latency in sending the Vector3) here’s the main part of code that I’m using right now.
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game.Players
local powerUpsFolder = workspace:WaitForChild("PowerUps")
local powerUpsChildren = powerUpsFolder:GetChildren()
local getVelocityEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("GetVelocity")
local fracturedSphere = script:WaitForChild("FracturedSphere")
local torsoVel = Vector3.zero
getVelocityEvent.OnServerEvent:Connect(function(player, velocity)
torsoVel = velocity
print(torsoVel)
end)
for i, v in pairs(powerUpsChildren) do
if v:IsA("BasePart") then
v.CanCollide = false
local fracturedSphereClone = fracturedSphere:Clone()
for i, fragment in pairs(fracturedSphereClone:GetChildren()) do
if fragment:IsA("BasePart") then
fragment.Transparency = 1
fragment.CanCollide = false
fragment.CustomPhysicalProperties = PhysicalProperties.new(0.01,0.1,1)
fragment.CanTouch = false
end
end
fracturedSphereClone:PivotTo(CFrame.new(v.Position))
fracturedSphereClone.Parent = powerUpsFolder
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
getVelocityEvent:FireClient(Players:GetPlayerFromCharacter(hit.Parent))
repeat wait() until torsoVel ~= Vector3.new(0,0,0)
for i, fragment in pairs(fracturedSphereClone:GetChildren()) do
if fragment:IsA("BasePart") then
fragment.Transparency = 0
fragment.Anchored = false
fragment.AssemblyAngularVelocity = Vector3.new(math.random(-20,20),math.random(-20,20),math.random(-20,20))
fragment.Velocity = ((fragment.Position - v.Position).unit * 50) + Vector3.new(0,100,0) + (torsoVel) -- Apply velocity away from the center
end
end
torsoVel = Vector3.zero
v:Destroy()
end
end)
end
end
Local Script:
getVelocityEvent.OnClientEvent:Connect(function()
getVelocityEvent:FireServer(torso.Velocity)
end)
This is the version with the RemoteEvent but like I said it doesn’t work very well. Thanks so much for reading this, please if you have any suggestions or are able to help please don’t hesitate to send a reply! Thanks!