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

How do I make a brick that gives specific team players money on touch?

Asked by 5 years ago
Edited 5 years ago
local ting = 0 --debouncer
local mon = script.Parent.Parent.MoneyValue
minstilregen = 2 -- change this to how ever many mins you want it to take before you can use again
tt = minstilregen * 60-- dont change

function onTouched(hit)

    if ting == 0 then --debounce check
    ting = 1 --activate debounce
    check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button

    if check ~= nil then --If a human is found, then

        local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
        local stats = user:findFirstChild("leaderstats") --Find moneyholder

        if stats ~= nil then --If moneyholder exists then
            local cash = stats:findFirstChild("Money") --Get money
            cash.Value  = cash.Value + mon.Value 
            script.Parent.Parent.Name = "Fixed" -- you should change this also
            script.Parent.Transparency = 0.8 
            wait(tt)-- do not change
            script.Parent.Parent.Name = "Pay amount: 100" -- change this to the title you want
            script.Parent.Transparency = 0.2
        end

    end

    ting = 0 --remove debounce
    end

end

script.Parent.Touched:connect(onTouched)

I want to give players of specific teams blocks to touch to gain money but I also don't want players of other teams to come in and touch the bricks for the money. I have a script that will give money on touch and it has a timer to ensure no spam but I can't find where to put the check team part of the script and when I try it will end up breaking most of the script. Any help would be appreciated! So just to clarify I need help adding into my current script a part that checks the humanoid that touched the part's team to make sure that everyone has a fair advantage this is my old script ive got a newer one but i still cant figure out what im doing wrong

0
lol and you expect to be helped without a script User#19524 175 — 5y
0
ScriptingHelpers is a community for teaching, we would love you to take a go at the script and we will support you in fixing the issue. crookedsuper 56 — 5y
0
Include your script User#5423 17 — 5y
0
Not even a Print Hello World script to start? ABK2017 406 — 5y
View all comments (3 more)
0
^^^ While I understand you are new here, they are right. This site is for problems you are running into with scripts you are working on or have worked on. Unfortunately, we cannot help you without a script. However, you can get started by making a few quick searches. For example, on Touched events and conditional statements. lunatic5 409 — 5y
0
No script included. DuckMaster11211 13 — 5y
0
sorry for not posting a script i was at work during the time i posted this and when I made it home i wasnt sure how to post the script but I posted a link to my inventory SonGarku 2 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
-- something like
-- script should be in the part that is to be touched

script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Humanoid then
        if hit.Parent.Name == game.Players.LocalPlayer.Name and game.Players.LocalPlayer.Team == "Name of the team" then
            -- what you want the script to do because I don't know how your currency script works
            wait(5) -- the number of seconds you want player to wait before getting money again
        end
    end
end)

-- hope it helps
0
thanks for your help, I've updated my old script but I'm still doing something wrong SonGarku 2 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
--leaderboard script
function onPlayerEntered(newplayer) 
local stats = Instance.new("IntValue") 
stats.Name = "leaderstats" 
stats.Parent = newplayer 
local money = Instance.new("IntValue") 
money.Name = "Money" 
money.Value = 1000
money.Parent = stats 
local wood = Instance.new("IntValue") 
wood.Name = "Pts" 
wood.Value = 10
wood.Parent = stats
end 

game.Players.ChildAdded:connect(onPlayerEntered)

minstilregen = 2
tt = minstilregen * 60
script.Parent.Touched:Connect(function (hit)
    if hit.Parent.Humanoid then
        if hit.Player.Name == game.Players.LocalPlayer.Name and game.Players.LocalPlayer.Team == "Factory" then

            local user = game.Players:GetPlayerFromCharacter(hit.Parent)
            local stats = user:findFirstChild("leaderstats")
            local mon = script.Parent.Parent.MoneyValue

            if stats ~= nil then
                local cash = stats:findFirstChild("Money")
                cash.Value  = cash.Value + mon.Value 
                script.Parent.Parent.Name = "Fixed"
                script.Parent.Transparency = 0.8 
                wait(tt)
                script.Parent.Parent.Name = "Pay amount: 100"
                script.Parent.Transparency = 0.2
            end
        end
    end
end)

this is my newer script and I know I'm missing something sorry I'm still new to this site and scripting in general

Log in to vote
0
Answered by 5 years ago

Ok, replying to FirezoneGamez, you should use his script but, he did it wrong, use this:

-- something like
-- script should be in the part that is to be touched

script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Humanoid then
        if hit.Parent.Name == game.Players.LocalPlayer.Name and game.Players.LocalPlayer.TeamColor = BrickColor.new("COLORHERE") -- Replace 'COLORHERE' with the color of the team.
            -- what you want the script to do because I don't know how your currency script works
            wait(5) -- the number of seconds you want player to wait before getting money again
-- Here is the script for the money,
local points = Instance.new("IntValue") --Change points to whatever you want, unless you want to keep it
    points.Name = "Cash" --Name of the Points, or whatever name you changed it to
    points.Parent = leaderstats
    points.Value = "None"
        end
    end
end)

-- hope it helps

Answer this question