Hey there!
I’m making a spawn car sell car system and need some help.
This is the current code which kinda works, and a brief explanation.
RegenScript
system = script.Parent
model = system.Car --
backup = model:Clone()
regen = system.Regen
function checkRegen()
if regen.Value == 1 then
model:remove()
wait(1)
model = backup:Clone()
model.Parent = system
model:MakeJoints()
end
end
regen.Changed:connect(checkRegen)
CarSold
local body = script.Parent.Body
local regen = body.Parent.Parent.Regen
while task.wait(1) do
body.DescendantRemoving:Connect(function(part)
if part.Name == "glass" then
print("Car sold")
wait(1)
regen.Value = 1
wait(1)
regen.Value = 0
end
end)
end
KillScript
local event = game.ReplicatedStorage.OpenGui
local sound = game.SoundService.SellSound
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
event:FireClient(plr)
sound:Play()
wait(2.5)
hit.Parent.Humanoid.Health = 0
end
end)
I am using Zednovs tycoon kit and I’m using the dropper PartCollector which checks for parts with a string called “Cash”.
I put the string “Cash” inside the part named “glass”.
When “glass” touches PartCollector it gets destroyed (and I get the Cash.Value).
The CarSold script checks if “glass” has been destroyed/removed.
If “glass” has been destroyed it changes regen.Value to 1.
RegenScript checks regen.Value.
If regen.Value = 1 then it removes the car model and spawns a new car.
KillScript plays a sound, opens a gui, and kills the player.
I need some help with optimizing this mess.
My goal is to have the CollectorPart freely in workspace, with a script that checks for the entire car model unlike my glass workaround.
The cash string should also be
- Placed inside the model, instead of a part.
or - Inside the script with a couple of
Instance.new("StringValue")
, to set the value, maybe?
I’m very open to ideas and feedback, and will be super grateful if anyone could help me out with this!