I don’t get what you mean but if I’m correct you want to do projectile visualization on the server as well?
That is alright unless you’d want everyone to see their character falling at an extremely slow pace, server-sided scripts running poorly, etc. Just handle projectile visualization on the client and you’re good to go, or check out SecureCast.
Yeah thanks a lot you helped me. I am just an infinite loop of fear that the server / client don’t sync together.
All the CFrames need to be replicated to all other clients and the server, so everyone else will see a laggy, unresponsive projectile. If you want to let a client have network ownership over the projectile, you will also need them to perform all hit detection checks and use a large margin of trust when validating because the server’s projectile will be noticeably delayed.
When the client that wants to spawn the projectile fires the server, they send the current synced timestamp returned by workspace:GetServerTimeNow()
to the server. The server can get the time taken to receive the projectile spawn event by subtracting this time from its workspace:GetServerTimeNow()
and decide based on that difference approximately where the projectile should be spawned (slightly forwards of the spawn position, i.e. studsPerSecond * offset
). When firing all clients, the server sends the received timestamp in the remote invocation, and all the clients move the projectile slightly forwards when they spawn it.
Once again, the issue with server-sided physics is that it will appear very laggy and slow to everyone. It’ll also take up quite a lot of bandwidth if you’re simulating a lot of unanchored, moving bodies.
If you want to observe this for yourself, create a new place and create a tool that when activated, spawns a part (with network ownership set to the server) and moves it with a linear velocity or impulse (in a server script). You will see that, on the client, the part freezes in place for about half a second before it starts moving. Additionally, you can run a loop on the server to spawn a part on the projectile’s CFrame to see just how delayed the client’s visualization of the part is from the server’s perspective. If you switch the network ownership to a client or shared, start a local server with 2+ players and you should see about the same results.
The server projectile does not need to be replicated to anybody. Its purpose is for authoritative validation, so none of the clients need to know it exists. I highly recommend parenting the server’s projectile under the workspace’s camera so you don’t have to spend any resources replicating an instance that all clients can simulate themselves.
so I made this prototype can you give me your thoughts and possible additions for performance and security?
CLiENT :
CLIENT
local UIS = game:GetService("UserInputService")
local Projectile = game.ReplicatedStorage.sphere
local Remote = game.ReplicatedStorage.RemoteEvent
local plr = game.Players.LocalPlayer
local char = plr.Character
local RS = game:GetService("RunService")
Remote.OnClientEvent:Connect(function(plr1,name,timer,cf) -- Renders projectile for other players
if plr1 == plr.UserId then
return
end
local PClone = game.ReplicatedStorage.sphere:Clone()
local zpos = workspace:GetServerTimeNow() - timer
PClone.Parent = workspace
PClone.CFrame = cf * CFrame.new(0,0,-2) * CFrame.new(0,0,-zpos)
PClone.Color =Color3.new(1, 0, 0)
RS.Heartbeat:Connect(function(dt) -- Update function
PClone.CFrame = PClone.CFrame* CFrame.new(0,0,-2*dt)
end)
end)
UIS.InputBegan:Connect(function(e)
if e.KeyCode == Enum.KeyCode.E then
local PClone = Projectile:Clone()
PClone.Parent = workspace
PClone.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0,0,-2)
Remote:FireServer(char.HumanoidRootPart.CFrame,workspace:GetServerTimeNow())
RS.Heartbeat:Connect(function(dt)-- Updates for the player who fired
PClone.CFrame = PClone.CFrame * CFrame.new(0,0,-2*dt)
end)
local part = Instance.new("Part",workspace) part.Parent = workspace part.Position=workspace.weas04.HumanoidRootPart.Position
end
end)
SERVER
local rs = game:GetService("RunService")
local Projectile = game.ReplicatedStorage.sphere
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,cf,er)
local char = plr.Character
print(game.ReplicatedStorage["sphere"])
game.ReplicatedStorage.RemoteEvent:FireAllClients(plr.UserId,"sphere",er,cf)
-- Hit Detection here will not use any part for hit box btw it would use .Heartbeat and take into account dtI tested it it synced with the client
end)
I tested it with my friends it worked fine
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.