I have been trying to make a car respawn that takes out money when you click it. I grouped the car with a brick. In the brick I put the following script, and a ClickDetector. What am I doing wrong. PS. Thanks to those who tried helping before on this!
location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()
function onClicked(hit)
if hit.Parent.Humanoid~= nil then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
cash = player:WaitForChild("leaderstats").Cash
if cash.Value >= 100 then
cash.Value = cash.Value - 100
back = save:clone()
wait(1)
back.Parent = location
back:MakeJoints()
else
print("Not enough Cash") -- Just tells you that they don't have enough Cash
end
end
end
script.Parent.Touched:connect(onClicked)

2 comments
We don't even know what's not working... Do you know how to read output? https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online
You used the wrong event if you are trying to use a ClickDetector. You used the Touched event of the part instead of the MouseClick event of ClickDetector