✓ Accepted answer
#Problem
if you look on line 10, your doing if stat == nil then return end, the == operator is for checking if something is equal to another thing so your just checking if :GetPlayerFromCharacter() returns nil then execute. You'd need to use the ~= operator which checks if something is not equal to another thing, Though you dont need to do that since :GetPlayerFromCharacter() returns nil if a player doesnt exist by itself. You should add a if statement to check if the parent of the PartThatTouched parameter has a humanoid.
#Deprecated functions and Clean code
:findFirstChild(), :connect(), transparency is deprecated dont use it, instead use :FindFirstChild(), :Connect() and Transparency. Also indent your code so its easier to read and looks cleaner and use local variables instead of global variables.
#More Things
Firstly, your checking if the debounce is true, though it is false without any lines setting it to true before the if statement. You also forgot alot of ends for the if statements, and if you dont have output enabled, enable it as it'll make debugging way easier.
local moneyToGive = 10
local debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildOfClass("Humanoid") and debounce == false then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local stats = player.leaderstats
local cash = stats.Cash
debounce = true
wait(.1)
if game.Workspace.Desperado.Body.Hay.Transparency == 0 then
cash.Value = cash.Value + moneyToGive
wait(2)
debounce = false
wait(5)
game.Workspace.Desperado.Body.Hay.Transparency = 1
end
end
end
end)
2 comments
if player == nil then return end, your just checking if it returns is nil -_-
That didn't really help...