Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't this work?

Asked by 8 years ago

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)

0
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 TheDeadlyPanther 2460 — 8y
0
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 BlackJPI 2658 — 8y

Answer this question