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

How do I make a seat that when you sit in it, it gives you money?

Asked by 4 years ago

I literally have no clue how to do this

local Cash = game.Players.LocalPlayer.leaderstats.Cash
if script.Parent.Humanoid.Sit == true then
Cash.Value = Cash.Value + 1

I tried doing that but it doesnt work. Can someone help me?

0
I made changes to my answer as per your comment CreationNation1 459 — 4y

4 answers

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

For this to work, the script must detect a change in the sit property. You can do so by doing this:

local Cash = game.Players.LocalPlayer.leaderstats.Cash
script.Parent.Humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
    if script.Parent.Humanoid.Sit == true then
        repeat
            wait(1)
            Cash.Value = Cash.Value + 1
        until
        script.Parent.Humanoid.Sit == false
    end
end)

I may have to provide more additional info, let me know if this doesn't work because you didn't give us enough context to understand what is wrong

0
it works but I how would I repeat it? I tried while true do proudCdthekitten 22 — 4y
0
I was able to repeat the script but when I stop sitting it still keeps going on proudCdthekitten 22 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I think what I would do is use collection service to tag the seats that you want to be able to give cash. Once you do that, use fire remote events for when the player sits and stands up from the seats. With a server script, detect when the remote events are fired and connect the function that will increase the player's cash. Here's the video that I thought of when I read your question, there's a longer tutorial that will go in depth how to use collection service. Roblox: Press E To Sit The scripts are provided to you in the description. Let me know if you have any questions.

Log in to vote
0
Answered by 4 years ago

Well, if you want a seat to give cash when a player sits on it then you would have to put a script inside the seat and put in the following:

script.Parent.ChildAdded:connect(function(weld)
    local char = weld.Part1.Parent
    local player = game.Players:FindFirstChild(char.Name)
    local leaderstats = player:FindFirstChild("leaderstats")
    local cash = leaderstats:FindFirstChild("Cash") --The cash found in your leaderstats, change it if you have your leaderstats different. 
    print(player)
    if player ~= nil then
        print('player is here',player)
        -- Now insert your script below
    cash.Value = cash.Value + 1 --This will give it when they sit, if you want it to keep giving them cash after a certain amount of time then go to the next script
    end
end)

Repeatedly giving cash:

local LoopTime = 10 --amount of seconds until player gets cash

script.Parent.ChildAdded:connect(function(weld)
    local char = weld.Part1.Parent
    local player = game.Players:FindFirstChild(char.Name)
    local leaderstats = player:FindFirstChild("leaderstats")
    local cash = leaderstats:FindFirstChild("Cash") --The cash found in your leaderstats, change it if you have your leaderstats different. 
    print(player)
    if player ~= nil then
        print('player is here',player)
        -- Now insert your script below
    while wait(LoopTime) do
        cash.Value = cash.Value + 1 
    end
    end
end)

Hopefully this helps you out! :)

Log in to vote
0
Answered by 4 years ago

Well firstly, using if script.Parent.Humanoid.Sit == true then makes it so if they are in the sit position, it gives money, so if they are on a regular chair, the script will make it count as you sitting.

So you should use an OnTouched function

amnt = 1 --how much you get for it!

function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Gold") -- Change the Score name!
                if (score~=nil) then
                    if h.Sit == true then
                        score.Value = score.Value + amnt
                    end
                end
            end
        end
    end
end

script.Parent.Touched:connect(onTouched)

This makes it so if the Player touches the Sit block, it will give free cash! Well since sit blocks are designed for you to sit as soon as you touch them, it wont really make a difference

for some reason the points will be added when you jump off C:

Answer this question