|
| 30 Nov 2017 11:25 AM |
| I made a touch script for when a car enters a part but It lags when said car enters, is there any way to make it not lag? :( |
|
|
| Report Abuse |
|
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
|
| 30 Nov 2017 11:31 AM |
| You'd have to post the script, or at least the part that's relevant |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2017 11:33 AM |
script.Parent.Touched:connect(function(hit) local Veh = nil if hit.Parent.Parent:FindFirstChild('DriveSeat') then Veh = hit.Parent.Parent:FindFirstChild('DriveSeat') end if Veh ~= nil then warn('FOUND VEHICLE') local Drive = nil for _,v in pairs(game.Players:GetChildren()) do if v.PlayerGui:FindFirstChild('Screen') then if v.PlayerGui.Screen:FindFirstChild('Car') then if v.PlayerGui.Screen.Car.Value == Veh.Parent then Drive = v end end end end if Drive ~= nil then if script.refilling:FindFirstChild(Drive.Name) then else warn('DRIVE NOT NIL') if Drive.PlayerGui:FindFirstChild('SCREENGUI') then warn('SCREENGUI FOUND IN PLAYER') else warn('SCREENGUI NOT FOUND IN PLAYER') local gui = script.Parent.SCREENGUI:Clone() gui.Home.Value = script.Parent gui.Parent = Drive.PlayerGui end end else warn('DRIVE = NIL') end end end) |
|
|
| Report Abuse |
|
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
|
| 30 Nov 2017 11:37 AM |
it lacks a debounce
local db = false
function yourfunction() if db then return end db = true (...) db = false end |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2017 11:38 AM |
| Would this effect other people if they wish to use this touching script too, like if one person is on it will it stop others from using it too? |
|
|
| Report Abuse |
|
|
TaaRt
|
  |
| Joined: 26 Apr 2009 |
| Total Posts: 5039 |
|
|
| 30 Nov 2017 11:46 AM |
It will make sure it won't get triggered multiple times while the code isn't done running, if two people touch it it'll likely work fine unless the code in the function is very slow to execute.
If you put the touch part in a localscript you could make sure it only reacts to that particular person or objects on their client(parent the localscript to the player though), but that'll require a remote if you wish the server to respond. It would make it a quicker process to find the player and their GUIs on the other hand |
|
|
| Report Abuse |
|
|
| |
|
|
| 30 Nov 2017 12:22 PM |
| Still lags when car drives through :/ |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2017 01:00 PM |
| Bump - Anyone have a fix or a better way of doing this? |
|
|
| Report Abuse |
|
|