But if I tween on the server, will it be a big deal? Like is it so bad? I mean I know it lags.
Not really, sure there will be some lag because Roblox servers are unoptimized for that thing but if itâs easy on you just do it on the server
Honestly at this point I must admit that the system I suggested needs to be polished more so Iâm sorry. Tweening in the server should be ok but be careful about how many tweens you have running at the same time though
Itâs impossible. There is always a delay between the server and the client and vice versa. The client needs to update anytime the server updates through replication.
I recommend you checking this out.
-- Server Script
local RS = game:GetService("ReplicatedStorage")
local rE = RS:WaitForChild("RemoteEvent")
local TS = game:GetService("TweenService")
local function tweenOnServer(object, charHrp)
local tweeningInfo = TweenInfo.new(1.5)
local goal = {CFrame = charHrp.CFrame}
TS:Create(object, tweeningInfo, goal):Play()
end
while true do
task.wait(5)
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
local char = player.Character
if char then
local hrp = char:FindFirstChild("HumanoidRootPart")
local clonedSphere = sphere:Clone()
clonedSphere.Parent = workspace
clonedSphere.CFrame = workspace.cylinder.CFrame
task.wait(0.1)
rE:FireClient(player, clonedSphere, hrp)
tweenOnServer(clonedSphere, hrp)
task.wait(1)
clonedSphere:Destroy()
end
end
end
Local script:
local RS = game:GetService("ReplicatedStorage")
local rE = RS:WaitForChild("RemoteEvent")
local TS = game:GetService("TweenService")
local function tweenOnClient(object, charHrp)
local tweeningInfo = TweenInfo.new(1.5)
local goal = {CFrame = charHrp.CFrame}
TS:Create(object, tweeningInfo, goal):Play()
end
rE.OnClientEvent:Connect(function(object, charHrp)
tweenOnClient(object, charHrp)
end)
- I added the missing
sphere
variable declaration in the server script. - The server script now fires the RemoteEvent for each player individually using
rE:FireClient(player, clonedSphere, hrp)
to avoid unnecessary data sent to all clients. - The server script calls the
tweenOnServer
function to tween the sphereâs position on the server side. - The client script calls the
tweenOnClient
function to tween the sphereâs position on the client side.
For #2 thatâs already what FireAllClients does with the benefit of not needing to loop for every player in the game
Edit: Also if youâre going to tween on the client anyway then thereâs no need for the server tween
The ball will just look glitchy because itâs being tweened at the server and at the client at the same time, in which the two has different runtime because of replication and ping, which I mentioned above.
Iâve made a blade ball âballâ myself before and I made it client sided only but it was 2 laggy so what I did was I replicated it from the server to client to all players.
I re-read the scripts on the main post very carefully and maybe this is what you actually want:
Server:
local players = game:GetService"Players"
local debris = game:GetService"Debris"
local remoteEvent = game:GetService"ReplicatedStorage".RemoteEvent
local sphere = game:GetService"ServerStorage".Part
local cylinderCFrame = workspace.Cylinder.CFrame
while true do
task.wait(5)
for _, player in players:GetPlayers() do
local hrp = (player.Character or player.CharacterAdded:Wait()).PrimaryPart
local sphereClone = sphere:Clone()
sphereClone.CFrame = cylinderCFrame
sphereClone.Parent = workspace
remoteEvent:FireAllClients(sphereClone, hrp.CFrame)
debris:AddItem(sphereClone, 2) -- Needs to be more than tween duration
end
end
Client:
local tweenService = game:GetService"TweenService"
local tweenInfo = TweenInfo.new(1.5)
game:GetService"ReplicatedStorage".RemoteEvent.OnClientEvent:Connect(function(sphereClone, hrpCFrame)
if not sphereClone then return end -- Just incase sphereClone is nil
tweenService:Create(sphereClone, tweenInfo, {CFrame = hrpCFrame}):Play()
end)
Wait, what makes Debris Service better than the :Destroy() Method and the script you edited is still a problem to hackers right? Since you didnât move the position of the sphere on the server.
Debris Service is just same as Destroy but with added timer (default is 5-8 seconds i think) but internally i assume it still calls Destroy() but also checks if object exists aswell so it doesnât error if the object was destroyed prior Destroy() being called again
debris makes sure the object still exists after the duration, before itâs destroyed else youâll get an error
I based these new scripts off of the ones on the main post, just optimized them a bit and made them tidier
I just tested it out and it turns out youâre right. I take back what I said. Also the Debris method is better than Destroy to be safe.
It is impossible to synchronize the client and server because both can be delayed cause of multiple things.
For exemple, the client can have delay because of its FPS, and the server can have delay because ressources taken, network ect⌠so even if you can minimize this delay for people that have a good PC and a good network, it will not be the same for everyone.
The only thing you can do in your case is to use a remote event, and Fire it from server to all client at each start and end of attacks.
Is it worth it to tween in both the client and server though? Like, what if tween it on the server only?
@T3_MasterGamer explained to me in a message that if you want to detect if the sphere hit something using Touched event on the server (which I also recommend for security purposes) and the sphere is being created on the server, you will need to move it on the server as well else the sphere will only move on the client causing the event to work incorrectly
If you tween it on the server only, itâs more likely that it will look laggy on the client.
Although if the client is experiencing network (internet) issues there will be a mismatch between the server tween and the client tween that I confirmed with a test just now (the server tween will complete before the client tween does even with the exact same tweenInfo configuration)
There isnât a way that I know that can solve this problem unfortunately
So, should I tween on both sides?
Think about the problem: Us programmers and game designers rely on the server to secure and/or relay (replicate) data being sent to players in the game. When you play the game using the Roblox Player or website (since Studio uses your PC as a server for testing) Roblox selects a random server thatâs available to host your game (from what I know it will try to find a server close to your locality when possible to minimize any delays). The server no matter where itâs located also relies on the clientâs internet connection to do its job, so if the client has a bad internet connection they might either miss data being sent altogether or retrieve the data too late. The only way to solve this problem is by forcing players to have a good internet connection but obviously this isnât possible and also has a risk to loose out on a lot of possible players since unfortunately good internet connections arenât cheap (I speak from personal experience, my internet connection enjoys randomly disconnecting when it feels like it)