Same game work diferently in roblox and in studio

and when i create welds nd tween only base part?

@Romeo_Duncan
your solution work as this



so dont work

Basically this.
Have one part on the server that represents the total size of the truck. You can use a few more parts if you need to. Its not bad to do this on the server, its just bad to do it with a lot of parts, so you should simplify it. The truck models only serve as an aesthetic so they should only exist on the client. Avoid :SetPrimaryPartCFrame as mentioned. You should weld the truck models to the hitbox on the client only. If you have multiple hitboxes per server, you can use welding there too.

Avoid using physics if you want deterministic results. Its much harder to get consistent results with it. Generally only use it if you are actually wanting physics simulation.

For moving the hitboxes, you don’t use renderstepped since it is on the server. You can use heartbeat or tweenservice as mentioned.

Now this makes the truck models latency sensitive. If the hitbox updates, and there is high latency, it will look like a teleport. To smoothen this out you can instead of welding to the hitbox you can tween the truck model to the hitbox (Again weld the truck to a part you want to tween). To compensate for latency regarding hitboxes, you can have a local hitbox tied to the truck that fires to the server and sends the position of the hitbox. You can then compare the client hitbox to the server hitbox and determine if it should be considered valid depending on the distance between each other.

2 Likes

ok, so what do i need to change

In simpler terms

  1. Have a server and client hitbox.
  2. Tween the server hitbox.
  3. Weld the truck to the client hitbox.
  4. Tween the client hitbox to the server hitbox.
  5. Report to server on client hitbox hits with position.
  6. Compare distance to the server and decide if that distance is valid to compensate for latency.
  7. Handle server hitbox position checks.

oh, so the server will just move hitbox and on client i use

hitbox.CFrame=serverhitbox.CFrame

You’ll need to tween if you want smooth movement regardless of latency.

It could be because of the loops.
How many loops do you have?

its because i tween many things at one time on server

I think your game is singleplayer. Why not do it on client?

a) exploits
b) i want to add tournament feature

For now I don’t think you shouldn’t focus on exploits, tweening on client == tweening on server when we are talking about exploiting (especially singleplayer). Why not finish the game first and make it smooth and after that you focus on fixing lagging and other stuff to include multiplayer. I suggest using two “games”
One for singleplayer mode and one for multiplayer mode.
You would teleport them to different places,

  1. Lobby
  2. Multiplayer / Singleplayer button (let player choose what they want to play)
  3. If singleplayer then do most of the stuff on client else do important stuff on server

a) for what to do first, contact contribution leader
b) its easier to make singleplayer same as multiplayer and just limit player to 1

still same…

ahhhhh, from watching network speed, i saw, that lags are based on recive

We could help you a lot more if we actually had the code to analyze.
Even if you say you implement what we say right we can’t actually verify if you’ve done something wrong or not.

Debugging an entire game is a very involved process.

localscript:

game.ReplicatedStorage.car.OnClientEvent:Connect(function (c,id) 
local model = game.ReplicatedStorage.cars[c]:Clone()
model.Parent=game.Workspace.vehicles
model.Name=id.."mesh"
while workspace.vehicles:FindFirstChild(id) ~= nil do
	game["Run Service"].Stepped:Wait()
	model.hitbox.CFrame=workspace.vehicles:FindFirstChild(id).hitbox.CFrame
end
model:Destroy()
end)

server script:

function detect (ac)
while ac ~= nil do
	if ac:FindFirstChild("hitbox")~=nil then
		local p = workspace.players:GetChildren()
		local pl = {}
		for _,v in pairs(p) do
			table.insert(pl,v.PrimaryPart)
		end
		local part = ac.hitbox
		local min = part.Position - (0.5 * part.Size)
		local max = part.Position + (0.5 * part.Size)
		local region = Region3.new(min, max)
		local parts = workspace:FindPartsInRegion3(region--[[,pl,math.huge]])
		for _,v in pairs(parts) do
			if v.Parent.Parent.Name=="players" then
				playerhit:FireClient(game.Players:FindFirstChild(v.Parent.Name),true)
				v.Parent.Parent=workspace.dead
				wait(1)
				v.Parent:Destroy()
			end
		end
	end
	game["Run Service"].Stepped:Wait()
end
end
local id=0
function car (p)
local r = Random.new()
while true do
	local ra=r:NextNumber(2,5)
	local c=r:NextInteger(1,#workspace.cars:GetChildren())
	
	wait(ra)
	local ac = workspace.cars[c]:Clone()
	id=id+1
	ac.Name=id
	ac.Parent=workspace.vehicles
ac:SetPrimaryPartCFrame(CFrame.new(Vector3.new(workspace.paths[p].Position.X,ac.PrimaryPart.Position.Y,ac.PrimaryPart.Position.Z)))
	ac.pos.Value=ac.PrimaryPart.CFrame
	local old = ac.pos.Value
	local ti = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut)
	local goal = {
		CFrame = 
CFrame.new(Vector3.new(ac.PrimaryPart.Position.X,ac.PrimaryPart.Position.Y,150))
	}
	local t = game.TweenService:Create(ac.hitbox,ti,goal)
	t:Play()
	game.ReplicatedStorage.car:FireAllClients(c,id)
	spawn(function () detect(ac) end)
	spawn(function () pos(ac,t) end)
end
end
function pos (ac,t)
while t.PlaybackState ~= Enum.PlaybackState.Completed do
	game["Run Service"].Stepped:Wait()
end
ac:Destroy()
end

I think, that the lag can be made by
a) network
b)detect()

You should be indexing top-level services using game:GetService(serviceName).
See this post for why.

1 Like

ok, i edited all services to :getService and i found mistake here

this is wrong order of these two lines
so it work smoother, but not completly without lag