generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Weird lag problem

Previous Thread :: Next Thread 
makerror is not online. 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 is not online. 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 is not online. 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 is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
19 Nov 2013 11:17 AM
cant fix lag, blame john
Report Abuse
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
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 is not online. 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
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
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
TheDarkMelon is not online. TheDarkMelon
Joined: 26 Jan 2013
Total Posts: 17713
19 Nov 2013 12:20 PM
[ Content Deleted ]
Report Abuse
makerror is not online. 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
DaMrNelson is not online. DaMrNelson
Joined: 27 Jul 2009
Total Posts: 4405
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image