So I have a local script that fires this event to a serverscript every time a player clicks which makes a part a few blocks in front of them:
game.ReplicatedStorage.aa.OnServerEvent:Connect(function(player)
local character = player.Character
local rootpart = character.HumanoidRootPart
local ray = Ray.new(rootpart.Position + (rootpart.CFrame.LookVector*10))
local hit, position = workspace:FindPartOnRay(ray, character)
local part = Instance.new("Part", workspace)
part.Size = Vector3.new(1, 1, 1)
part.Shape = "Ball"
part.CanCollide = false
part.Anchored = true
part.Position = position
wait(1)
part:Destroy()
end)
And I want it to be very responsive but it’s delayed because the server doesn’t update the character’s position and look vector right away.
I could send the position and look vector values from the client to the server, but exploiters could easily send different values.
Is there any way to work around the delay without letting exploiters take advantage of the remote event?
I would not send the Vectors from the client, because as you said, an exploiter could easily fire the remote event with whatever parameters they want. Plus, performing the calculations on the client, versus on the server, is not going to minimize much delay at all. Most of the lag time is going to be caused by the server replicating the part to the client, not the raycast checks.
However, if you are annoyed by the slight hold up of replication, you could first create the part on the client, and then tell the server to replicate it to everyone else. This way the player who creates the part gets to see it almost instantaneously, and the other players shortly after.
Let’s say I wanted to create the same ray from the server but this time I wanted it to damage a player that it hit, would there be less time lag now because the server won’t have to replicate a part to the client?
Yes, any part you create on the client will appear faster to the local player, since it does not need to replicate. You will still have to wait the same duration for the user to be damaged, but you can decrease the part spawn time by making it client sided first.