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 » Scripters
Home Search
 

Re: Touching Script

Previous Thread :: Next Thread 
FlamingGamez is not online. FlamingGamez
Joined: 22 Jan 2015
Total Posts: 354
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 is online. 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
FlamingGamez is not online. FlamingGamez
Joined: 22 Jan 2015
Total Posts: 354
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 is online. 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
FlamingGamez is not online. FlamingGamez
Joined: 22 Jan 2015
Total Posts: 354
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 is online. 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
FlamingGamez is not online. FlamingGamez
Joined: 22 Jan 2015
Total Posts: 354
30 Nov 2017 11:52 AM
Alright thanks.
Report Abuse
FlamingGamez is not online. FlamingGamez
Joined: 22 Jan 2015
Total Posts: 354
30 Nov 2017 12:22 PM
Still lags when car drives through :/
Report Abuse
FlamingGamez is not online. FlamingGamez
Joined: 22 Jan 2015
Total Posts: 354
30 Nov 2017 01:00 PM
Bump - Anyone have a fix or a better way of doing this?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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