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

How can I make it so a player can only fire the function off once?

Asked by 8 years ago

Thanks to your generous help this script is almost fully functional! However I need some more help. I've been struggling to figure out one last kink. This is what I need help with:

So when you step on the brick it checks your group. If you are in one of the accepted groups, either marcano or police at this point, it searches the game for all other players in that group and gives them the money loop. However a player can step on the brick as many times as they want and add an additional loop for every touch. This is a problem. Now I placed a stringvalue inside capture point named "Owner" and on touch it changes the value to the group that you are in. Is there a way I can utilize this strategy to fire off the function ONLY if the value inside the capture point is NOT equal to the touched player's value? I'm also curious as to if there is a way to break the money loop if the value of "Owner" is changed.

Thank you if you read this far!!! Scripting Helpers has helped me so much on my endeavors in game creation, and any advice or suggestions mean the world to me. : )))))

local money = "Money"
local amount = 50
local timedelay = 2
local marcano = 2959195
local police = 3003695
local point = script.Parent


point.Touched:connect(function(part)
    local plr =  game.Players:GetPlayerFromCharacter(part.Parent)
    print ('The capture point was touched')
    if plr then
        if plr:IsInGroup(police) or plr:IsInGroup(marcano) then
            print ('The player is in an accepted group')
            point.BrickColor = BrickColor.new("Black")
            if plr:IsInGroup(police) then
                plr.Group.Rank.Value = police
            elseif plr:IsInGroup(marcano) then
                plr.Group.Rank.Value = marcano
            end
            for _,v in pairs(game.Players:GetChildren()) do
                if v:IsInGroup(police) then
                    v.Group.Rank.Value = police
                elseif v:IsInGroup(marcano) then
                    v.Group.Rank.Value = marcano
                end
                if plr.Group.Rank.Value == v.Group.Rank.Value then

            wait (timedelay)

            while true do
                        wait (timedelay)
                    game.Workspace.Capture.Owner.Value = plr.Group.Rank.Value
                    v.Wealth[money].Value = v.Wealth[money].Value + amount

    end

                            print ('The player is not in an accepted group!')
                        end
                    end
                end
            end

end)





Here is what I'm trying to play around with.

if plr.Group.Rank.Value ~= point.Owner.Value then

1 answer

Log in to vote
0
Answered by 8 years ago

Add an additional check when the part is touched, check if the point is aleredy captured by the same group? Else if a other group touches it, it breaks the loop.

Ad

Answer this question