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

The script gives money to players that are not in the same group?

Asked by 8 years ago

When the part is touched this script is supposed to look for players in the game in the same accepted group as the player that touched the part and give them money. However it everyone money when the part is touched. Where am I going wrong? Thank you for your time!! :)

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')
for _,v in pairs(game.Players:GetChildren()) do
if v:IsInGroup(police) or v:IsInGroup(marcano) then
v.Wealth.Money.Value = v.Wealth.Money.Value + 100


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




end
    end
        end
            end
                end)

3
Can you tab your code correctly, this is a real pain to read :/ User#5423 17 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago
Edited 6 years ago

The problem is that when you are on this:

for _,v in pairs(game.Players:GetChildren()) do
if v:IsInGroup(police) or v:IsInGroup(marcano) then
v.Wealth.Money.Value = v.Wealth.Money.Value + 100

That script checks if a player is inside any of those groups, so it gives it to everyone, you would have to check if v is in the same group as plr So I would do:

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')
            if plr:IsInGroup(police) then
                local PlrRank = "police"
            elseif plr:IsInGroup(marcano) then
                local PlrRank = "marcano"
            end
            for _,v in pairs(game.Players:GetChildren()) do
                if v:IsInGroup(police) then
                    local VRank = "police"
                elseif v:IsInGroup(marcano) then
                    local VRank = "marcano"
                end
                if PlrRank == VRank then
                    v.Wealth.Money.Value = v.Wealth.Money.Value + 100
                else
                    print ('The player is not in an accepted group!')
                end
            end
        end
    end
end)

Hope it helps!

EDIT:

Add the word local before PlrRank and VRank like I did above.

0
will this be an issue? https://gyazo.com/6856507f17bf94650882112c11482962 i'm not sure how to solve it. marsupicide 60 — 8y
0
also thank you for responding so fast!! marsupicide 60 — 8y
0
Yes, I know how to fix that issue, all you have to do is add the word local before a variable name when you are creating them. I edited the answer so that it does not give you those warnings, and no problem, I like helping as soon as possible. LisaF854 93 — 8y
0
Did this fix your issue? LisaF854 93 — 8y
0
yes!! marsupicide 60 — 8y
Ad
Log in to vote
1
Answered by
doomiiii 112
8 years ago
Edited 8 years ago

Right now, you are giving money to players in any group because if a or b then f() end means that f() will run if EITHER condition a or b is true; so, in your case, money is handed out to anyone who is in police and also to anyone in marcano:

if plr:IsInGroup(police) or plr:IsInGroup(marcano) then

One way to solve this would be the use of an IntValue to determine the owner group:

  1. In the editor, add a new IntValue as a sibling to this script (make sure they have the same parent)

  2. Call it GroupId

  3. Assign the id of the owning group to GroupId

  4. Then change your if line from above to:

if plr:IsInGroup(script.Parent.GroupId.Value) then

This will now only give money to the group whose id you have defined in GroupId :)

0
thank you! your resolution makes sense, i'll try it!!! :)))))))))) marsupicide 60 — 8y
0
Note that you will now need two objects, both with this script and the GroupId (IntValue), one per group :) doomiiii 112 — 8y

Answer this question