Hello!
I am trying to make a script that, when the player is sitting on the vehicle seat and driving, gives the player money every second. I have a whole script down, it just doesn't work. Any ideas why?
function touch(hit)
local player = hit.Parent
local stats = player:findFirstChild("leaderstats")
local add = 110
if player.Humanoid and script.Parent.SeatWeld then
script.Parent.sitting.Value = 1
else
script.Parent.sitting.Value = 0
end
if script.Parent.sitting.Value == 1 then
wait()
if script.Parent.Throttle == 1 then
wait(1)
local money = stats:findFirstChild("money")
money.Value = money.Value + add
end
end
end
script.Parent.Touched:connect(touch)
I have a leaderboard with a money section, so I don't understand why it isn't working. It has no errors, and actually absolutely nothing shows up in the analysis section. I checked to see if the sitting value at least changed, but it did not. Help would be greatly appreciated!
EDIT: After Aquathorn321 answered, I tweaked the script and it is now:
script.Parent.Touched:connect(touch)
function touch(hit)
local character = hit.Parent
local stats = character:findFirstChild("leaderstats")
local player = game.Players:GetPlayerFromCharacter(character)
local add = 110
wait(1)
if character.HumanoidRootPart and script.Parent.SeatWeld then
print("Player sitting")
wait()
if script.Parent.Throttle == 1 then
wait(1)
local money = stats:findFirstChild("money")
money.Value = money.Value + add
end
end
end
script.Parent.Touched:connect(touch)
When a player sits on the seat it DOES print "Player sitting" but it doesn't give the money, it comes up with an error saying attempt to call a nil value for the money.Value part. Any help?

1 comment
Where do I put this script, I want the same script, But I dont know where to put it