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)
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)