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

I need help with this script that adds money directly to the player on touch. Please help?

Asked by 6 years ago

I am making a sandbox tycoon and i have a money collector that adds money directly to the players cash, but it only works on the first one that touches it. Please help!

function onTouched(hit) 
    if hit.Name == "Cash" then
    game:GetService("ReplicatedStorage").Owner1.OnServerEvent:connect(function(player)
    player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + hit.Value.Value --Gives money based on value in money
    hit:remove()
    end)
end
end
script.Parent.Touched:Connect(onTouched)

Also, for some reason it adds a touch interest in the part that has the script in it.

0
Bump giantjdd 5 — 6y
0
Bump giantjdd 5 — 6y
0
Bump giantjdd 5 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Im not sure what your asking for but this script gives you cash!

local ting = 0

function onTouched(hit)

    if ting == 0 then 
    ting = 1 
    check = hit.Parent:FindFirstChild("Humanoid") 

    if check ~= nil then 

        local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
        local stats = user:findFirstChild("leaderstats") 

        if stats ~= nil then
            local cash = stats:findFirstChild("Cash") 
            cash.Value  = cash.Value +10000000 
            wait(2) 
        end

    end

    ting = 0 
    end

end

script.Parent.Touched:connect(onTouched)
0
Thanks, but thats not what i was asking, im saying the collector i have works ontouch and adds the value that is in the thing that touches it to your cash directly, but it only works for the first "cash" that touches it and then when they touch it, it doesnt do anything giantjdd 5 — 6y
0
Add the Debounce sturdy2004 110 — 6y
0
Do you mean just add wait? Because ive tried that, but it didnt work and it removes it instantly anyways so how would it help? giantjdd 5 — 6y
0
No Wait and debounce are diffrent sturdy2004 110 — 6y
Ad

Answer this question