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

How to make this onTouch script do the function if called?

Asked by 4 years ago

Hi, I got this script of YouTube for a touch event that gives player stored cash, but how I could I alter this script to give the same variables but without having to touch (such as when the player joins, or a module, or being called, etc...) Any help is appreciated.


local ting = 0 --debouncer

function onTouched(hit)

if ting == 0 then --debounce check
ting = 1 --activate debounce
check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button

if check ~= nil then --If a human is found, then

    local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
    local stats = user:findFirstChild("leaderstats") --Find moneyholder

    if stats ~= nil then --If moneyholder exists then
        local cash = stats:findFirstChild("Money") --Get money
        cash.Value  = cash.Value +1000 --increase amount of money by the number displayed here (1000)
        wait(100) --wait-time before button works again
    end

end

ting = 0 --remove debounce
end

end

script.Parent.Touched:connect(onTouched)

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

You can add the Player Cash by them join by using .PlayerAdded Here is how you do it :

game.Players.PlayerAdded:Connect(function(Player)
    Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 100 -- Change the Stat Name and Value if needed
end)
0
No I'm asking how after that the player is required to touch the part to get cash, how could I remove that part and just give the player cash without having to touch it, such as when the player joins? NotOriginal12345 9 — 4y
0
Oh that might require DataStore to let the player join again and get cash Nguyenlegiahung 1091 — 4y
Ad

Answer this question