makerror
|
  |
| Joined: 29 Aug 2011 |
| Total Posts: 493 |
|
|
| 19 Nov 2013 11:02 AM |
I have spaceship script, which uses keydown and keyup events. Everything works fine in solo mode, but in real game if there're more than 1 player, only 1 player can control ship smooth and without lag, everyone else in game are lagging script: _____________________________________________________ local player = game.Players.LocalPlayer local mouse = player:GetMouse() local ship = player.Character.Ship local main = ship.Main -- local v = main.BodyVelocity local m = main.Motor -- local Power = ship.Speed.Value local Rotate = Power -(Power/3)
local t = {w = false, a = false, s = false, d = false} mouse.KeyDown:connect(function(k) t[k] = true end) mouse.KeyUp:connect(function(k) t[k] = false end) function Update() if t.w and t.a then v.velocity = Vector3.new(Rotate,0,-Rotate) m.CurrentAngle = math.rad(315) elseif t.w and t.d then v.velocity = Vector3.new(Rotate,0,Rotate) m.CurrentAngle = math.rad(225) elseif t.s and t.a then v.velocity = Vector3.new(-Rotate,0,-Rotate) m.CurrentAngle = math.rad(45) elseif t.s and t.d then v.velocity = Vector3.new(-Rotate,0,Rotate) m.CurrentAngle = math.rad(135) elseif t.w then v.velocity = Vector3.new(Power, 0, 0) m.CurrentAngle = 4.712 -- 270 elseif t.a then v.velocity = Vector3.new(0, 0,-Power) m.CurrentAngle = 0 elseif t.s then v.velocity = Vector3.new(-Power, 0,0) m.CurrentAngle = 1.570 -- 90 elseif t.d then v.velocity = Vector3.new(0, 0, Power) m.CurrentAngle = 3.141 -- 180 end end
while true do wait(0) if t.w or t.a or t.s or t.d then Update() else v.velocity = Vector3.new(0, 0, 0) end end _______________________________________________________ It's local script. |
|
|
| Report Abuse |
|
|
Mikesly
|
  |
| Joined: 07 Sep 2007 |
| Total Posts: 4593 |
|
|
| 19 Nov 2013 11:08 AM |
| Try putting wait(1) at the beginning of it. That always fixed my mutltiplayer issues. |
|
|
| Report Abuse |
|
|
makerror
|
  |
| Joined: 29 Aug 2011 |
| Total Posts: 493 |
|
|
| 19 Nov 2013 11:16 AM |
It's not worked
I think the problem is "Entry lag", anyone know how to fix it? |
|
|
| Report Abuse |
|
|
breuning
|
  |
| Joined: 30 Oct 2008 |
| Total Posts: 4268 |
|
| |
|
|
| 19 Nov 2013 11:21 AM |
This issue happens because of server latency. The person controlling the ship is... well, controlling it. For that reason, they always know exactly where the ship is. However, other players have to wait for the controller's computer to send the server the information on where the ship is, and then the server to send it to them.
A way to minimize this "lag" effect would be to set up your key events (in the LocalScript) to change a few BoolValues named "KeyADown", "KeySDown", "KeyDDown", etc and have a server-side Script (just a normal Script) move the ship from those values.
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
makerror
|
  |
| Joined: 29 Aug 2011 |
| Total Posts: 493 |
|
|
| 19 Nov 2013 12:04 PM |
| If I understood correct, player after keydown event set those bool values to true/false and main(other) script to check them, so that means 1 script going to control all ships inside server? |
|
|
| Report Abuse |
|
|
|
| 19 Nov 2013 12:14 PM |
No, not one script. This is what I mean (in simple point form)
- Model in ship named "Keys" - Different BoolValues for used keys - LocalScript controls these BoolValues when keys are pressed - Script inside each ship - Script moves the ship the exact same way the LocalScript would, except it uses the BoolValues as key events
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|
| |
|
makerror
|
  |
| Joined: 29 Aug 2011 |
| Total Posts: 493 |
|
|
| 19 Nov 2013 12:56 PM |
Feeling like a noob
Script moves the ship the exact same way the LocalScript would, except it uses the BoolValues as key events
I need to use not local script? and if bool value changes, change velocity too? |
|
|
| Report Abuse |
|
|
|
| 19 Nov 2013 04:54 PM |
All that did was minimize the lag effect. There is no way to completely remove it all (that I know of).
Wiki Profile: http://wiki.roblox.com/index.php/User:Nelson |
|
|
| Report Abuse |
|
|