Sr.black Posted September 16, 2023 Share Posted September 16, 2023 (edited) Please Help me to fix the script dont working the script destroy vehicles stuck in water after 4 seconds but dont working can you fix it please? client: function onVehicleStuckInWater(vehicle) local delay = 4 -- in seconds timer.start(delay, function() destroyVehicle(vehicle) end) end server: local vehiclesInWater = {} function onVehicleEnterWater(vehicle) vehiclesInWater[vehicle] = true end function onVehicleLeaveWater(vehicle) vehiclesInWater[vehicle] = nil end function onTick() for vehicle, _ in ipairs(vehiclesInWater) do local z = getVehicleZ(vehicle) if z < -1.5 then triggerClientEvent("onVehicleStuckInWater", getVehiclePlayer(vehicle), vehicle) end end end Edited September 16, 2023 by Sr.black Link to comment
Shady1 Posted September 16, 2023 Share Posted September 16, 2023 2 hours ago, Sr.black said: Please Help me to fix the script dont working the script destroy vehicles stuck in water after 4 seconds but dont working can you fix it please? client: function onVehicleStuckInWater(vehicle) local delay = 4 -- in seconds timer.start(delay, function() destroyVehicle(vehicle) end) end server: local vehiclesInWater = {} function onVehicleEnterWater(vehicle) vehiclesInWater[vehicle] = true end function onVehicleLeaveWater(vehicle) vehiclesInWater[vehicle] = nil end function onTick() for vehicle, _ in ipairs(vehiclesInWater) do local z = getVehicleZ(vehicle) if z < -1.5 then triggerClientEvent("onVehicleStuckInWater", getVehiclePlayer(vehicle), vehicle) end end end but I created a piece of code for you, maybe it will help you, local vehicleChecker function checkVehiclesInWater() for _,vehicle in ipairs(getElementsByType("vehicle")) do if isElementInWater(vehicle) then destroyElement(vehicle) end end end vehicleChecker = setTimer(checkVehiclesInWater, 4000, 0) I don't understand exactly what you are trying to do, I didn't understand anything when I examined your code Link to comment
Hydra Posted September 17, 2023 Share Posted September 17, 2023 On 16/09/2023 at 12:27, Sr.black said: Please Help me to fix the script dont working the script destroy vehicles stuck in water after 4 seconds but dont working can you fix it please? client: function onVehicleStuckInWater(vehicle) local delay = 4 -- in seconds timer.start(delay, function() destroyVehicle(vehicle) end) end server: local vehiclesInWater = {} function onVehicleEnterWater(vehicle) vehiclesInWater[vehicle] = true end function onVehicleLeaveWater(vehicle) vehiclesInWater[vehicle] = nil end function onTick() for vehicle, _ in ipairs(vehiclesInWater) do local z = getVehicleZ(vehicle) if z < -1.5 then triggerClientEvent("onVehicleStuckInWater", getVehiclePlayer(vehicle), vehicle) end end end you forgot to use addEvent for your function to work when you want to trigger it Client function onVehicleStuckInWater(vehicle) local delay = 4 -- in seconds timer.start(delay, function() destroyVehicle(vehicle) end) end addEvent("onVehicleStuckInWater", true) addEventHandler("onVehicleStuckInWater", root, onVehicleStuckInWater) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now