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)
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.
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:
In the editor, add a new
IntValue
as a sibling to this script (make sure they have the same parent)Call it
GroupId
Assign the id of the owning group to
GroupId
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
:)