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

How do I make this script give the player money when they drive?

Asked by 9 years ago

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?

0
Where do I put this script, I want the same script, But I dont know where to put it DustyTyrannosaurus 0 — 4y

1 answer

Log in to vote
0
Answered by 9 years ago

I went ahead and rewrote the script. See if this works. If not, all you should have to do is put a conditional when searching for whether whatever hit the brick has a player model linked to it.


local add = 110 script.Parent.Touched:connect(function(hit) local character = hit.Parent local player = game.Player:GetPlayerFromCharacter(character) if player then if script.Parent:FindFirstChild("SeatWeld") then script.Parent.sitting.Value = 1 wait() if script.Parent.Throttle == 1 then wait(1) local money = stats:FindFirstChild("money") money.Value = money.Value + add end else script.Parent.sitting.Value = 0 end end end)
0
Thank you! Only problem now is that it says humanoid is not a valid member of Player. Any ideas? blueburns 10 — 9y
0
daheck? the entire script on the bottom is within the codeblock, but for some reason it's not registering. And it put the normal text inside the codeblock? aquathorn321 858 — 9y
0
Fixed aquathorn321 858 — 9y
0
where do I put the script? DustyTyrannosaurus 0 — 4y
0
@DustyTyrannosaurus you're about five years late... you put it in the seat aquathorn321 858 — 4y
Ad

Answer this question