hello
i have a game that gets really laggy because there is a lot of cars in the game at once.
i need some help on getting the cars to destroy them self after a certain amount of time eg. 30 seconds
hello
i have a game that gets really laggy because there is a lot of cars in the game at once.
i need some help on getting the cars to destroy them self after a certain amount of time eg. 30 seconds
You can use the service Debris and it has a function perfect for you. It is :AddItem().
--Local script in any service that allows localscripts to run
local player = game.Players.LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid.Seated:Connect(function(isSeated, seat) -- isSeated is whether the humanoid is sitting down, seat is the actual part.
-- create a remote event in replicatedstorage
game.ReplicatedStorage.RemoteEvent:FireServer(isSeated, seat) -- change RemoteEvent to the name that you have on your remoteEvent.
end)
-- Server script in serverscriptservice
local carModel = game.Workspace.Car -- change this with the name of the car model
local debris = game:GetService("Debris")
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, isSeated, seat)
if not isSeated and seat then
debris:AddItem(carModel, 30) -- add item basically schedules a deletion for a set amount of time.
end
end)
You can read more about Debris here (i'm a nice guy so i decided to help, even though you didn't try it.)
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
This website isn't really about having other people do your work. Can you at least attempt this?
sorry
https://scriptinghelpers.org/help/how-post-good-questions-answers