I am making a game where you drive cars for money, but players can just spawn endless cars. i have made an attribute that has the name of the player who owns the car but not anything else
You should have the vehicles spawned into a Workspace.Folder thats specifically for vehicles only and have those vehicle with attribute of who spawned. Then you need a For loop to check through the Folder in the workspace to make sure a player do not have vehicle spawned already before spawning another one on server side script. Whatever spawns the vehicle.
Also when setting the Vehicle model’s attribute, You should use UserId instead of usernames!
Code sample
local Allow = true
for _, Vehicle in pairs(workspace["Vehicle folder"]:GetChildren()) do
if Vehicle and Vehicle:GetAttribute("Owner") == player.UserId then
Allow = false
break
end
end
if Allow == true then
-- Spawn cars
end
When a player spawns a car, the vehicle model is renamed to “[Username]_Car.” Before spawning a new car, the system checks whether a vehicle with this name already exists. If it does, delete the old car and spawn the new one.
lets just say ive tried that and it was a disaster
Why? I have implemented a system like that to my game and it works perfectly fine.
Either way works lol, in my opinion and from my experience. This is more recommended if its individuals vehicle. They are spawnable models by players and they should be parented in a Folder. Also its best to always use UserId in anyway to prevent future problems.
thanks! I just changed 2 lines of code, and it was working a little better.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.