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

How do I give the player money onTouch?

Asked by 7 years ago

I have multiple blocks named the same thing inside a folder, and instead of putting a script into each block I want to put a script into serverscriptservice that does what the script in the block would do.

The folder is located here: model = game.Workspace.Storage.Bits

I want to add 1 Money to the players leaderstat whenever they touch the "bit". This is what I have:

--Put all the parts in a model

money = player.leaderstats.Money.Value -- locates money

model = game.Workspace.Storage.Bits
DownTime = 3.5 --the time the parts are gone

function bit(part)
    model.bit:remove()
end



for i,v in pairs(model:GetChildren()) do
    v.Touched:connect(function(hit)
        if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
        money = money + 1 -- adding the money here
            bit(v)
        end
    end)
end

1 answer

Log in to vote
0
Answered by 7 years ago

i think i did what you did with the server script and stuff

 local money = player.leaderstats.Money.Value 

doesnt work

it needs to be

money.Value  = money.Value + 1
--Put all the parts in a model
game.Players.ChildAdded:connect(function(player) -- if it doesnt work, change to PlayerAdded, ChildAdded worked more then PlayerAdded in studio

local money = player.leaderstats.Money -- locates money

local model = game.Workspace.Storage.Bits
local DownTime = 3.5 --the time the parts are gone

function bit(part)
    model:remove()
end



for i,v in pairs(model:GetChildren()) do
    v.Touched:connect(function(hit)
    print('Touched')
        if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
        money.Value  = money.Value + 1 -- adding the money here
            bit(v)
        end
    end)
end


end)
Ad

Answer this question