Hey developers. I have been having trouble with an issue that seems really simple in my eyes. Might just be my lack of experience with tweening.
I am working on a tween-based tram system with multiple stops. I have the system set up so that the tween plays on the client and then updates the position on the server, using RemoteEvents.
The only problem is that the position updating isn’t working. Of course this causes many issues, such as the tram being out of sync for multiple players, leaving and joining, etc.
Server Code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Remote = ReplicatedStorage.Remotes.tram.sequence
local UpdateRemote = ReplicatedStorage.Remotes.tram.updatePosition
local Tram = game.Workspace.Tram
local TramRoot = Tram.TramRootPart
local TramWaypoints = game.Workspace.TramWaypoints
local distance
local TWEEN_TIME = 15
local TweenInformation = {
Time = 10,
Style = Enum.EasingStyle.Sine,
Direction = Enum.EasingDirection.In,
Repeat = 0,
Reverse = false,
Delay = 0
}
local Quadrant4Dictionary = {
CFrame = TramRoot.CFrame * CFrame.new(TramRoot.Size.X + -(TramRoot.Position.X - TramWaypoints.TramQuadrant4.Position.X),0,0)
}
local ReturnMainDictionary = {
CFrame = TramRoot.CFrame * CFrame.new(TramRoot.Size.X + (TramRoot.Position.X - TramWaypoints.TramMain.Position.X),0,0)
}
wait(5)
Remote:FireAllClients(TweenInformation,Quadrant4Dictionary,TramRoot)
UpdateRemote.OnServerEvent:Connect(function(player, object)
TramRoot.Position = object.Position
end)
Client Code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Remote = ReplicatedStorage.Remotes.tram.sequence
local UpdateRemote = ReplicatedStorage.Remotes.tram.updatePosition
Remote.OnClientEvent:Connect(function(Info,Dictionary,Object)
local Information = TweenInfo.new(Info.Time,Info.Style,Info.Direction,Info.Repeat,Info.Reverse,Info.Delay)
local Tween = TweenService:Create(Object,Information,Dictionary)
Tween:Play()
Tween.Completed:Connect(function(Object)
UpdateRemote:FireServer(Object)
end)
end)
Any help would be appreciated. Thank you!