Hello. Im trying to make a car despawner for my open world car game. I have a functional despawner but the problem i am having is that after the player presses the button it despawns all the cars that aren't occupied by any player. This includes random players outside their car for good reasons, like people role playing as police officers and conduction a traffic stop. Ive gotten a despawner working by using a GUI Text Button that has a LocalScript as a child. It then uses a RemoteEvent that triggers a server script applied for every different car i have added to my game. The problem is that the code has no way of telling which was being used by what player. This has been what has really confused me.
Here is the local script that is tied to the button
local deletecarButton= script.Parent:WaitForChild("DeleteCarButton")
local CrownVicDeleteScript = game.ReplicatedStorage.CrownVicPoliceDespawnerButton
local DodgeInterceptorDeleteScript = game.ReplicatedStorage.DodgeChargerInterceptorDespawn
deletecarButton.MouseButton1Click:Connect (function()
CrownVicDeleteScript:FireServer()
DodgeInterceptorDeleteScript:FireServer()
end)
As you can see as soon as my button is pressed it fires remote events for the 2 cars i have coded so far.
Here is the code on the car seats
local seat = script.Parent
local car = seat.Parent
local CrownVicDespawnerButton = game.ReplicatedStorage.CrownVicPoliceDespawnerButton
CrownVicDespawnerButton.OnServerEvent:Connect(function()
if not seat.Occupant then
car:Destroy()
end
end)
This code checks to make sure no one is in the car. Then despawns it. The problem im having is it checks for all cars of this model that have been spawned, not just the one the player using the button has spawned. So it deletes every non occupied car of this type including ones being still used just not currently occupied.
Ive tried everything i could think of but i can not find a way to make it so it knows what car is whose.
Any help is appreciated , Thanks

5 comments
BeingUsed should be a bool because Int are numbers so it will error
BoolValue*
Thanks for the explanation it does make more since now. The one thing im confused about is how do i make it so if the player is done using the car (spawns a new one , leaves the game, or switches teams) it makes the car go back to being despawnable?
It will not error because you're not using the IntValue as a book but rather as a way to tag a car on whether is it being used or not. I will make a script and let you know on how you can untag the car in a bit!
Ok thanks