Code;
local event = Instance.new("RemoteEvent") event.Parent = game.ReplicatedStorage event.Name = "RCL" event.OnServerEvent:connect(function() local gunsadded = false local bricktops = game.ReplicatedStorage.Maps.Bricktops for i,v in ipairs(game.Players:GetChildren()) do v.CharacterAdded:connect(function(character) if v.TeamColor == BrickColor.new("Sand red") or v.TeamColor == BrickColor.new("Sabd blue") then if game.Workspace.CurrentMap:IsAncestorOf(game.ReplicatedStorage.Maps.Bricktops) then for i,x in ipairs(WeaponStorage.RCLWeapons:GetChildren()) do if not gunsadded then gunsadded = true if x:IsA("Tool") then x:Clone().Parent = v.Backpack gunsadded = false end end end end end end) end
Purpose;
The event gets all the players in the game, and checks if they're on either the Bright blue or Bright red team, and checks whether "Bricktops" is present within workspace.CurrentMap. If the players are on the blue and red teams and Bricktops is present, then it gives the players weapons every time they respawn.
Idea of what the problem is;
if game.Workspace.CurrentMap:IsAncestorOf(game.ReplicatedStorage.Maps.Bricktops) then
Notes;
RemoteEvent is fired in another script when a TextButton is clicked.
Everything was running somewhat smoothly last night until I added :IsAncestorOf
I also tried using :IsDescendantOf
As DevSean pointed out, line 9 has a typo.
Assuming Bricktops is a child of CurrentMap when line 10's if statement is executed, it should error that Bricktops is not a valid member of Maps. Is this the error you're receiving?
If so, a solution would be to give Bricktops a variable in the global environment, rather than attempting to reference it in the if statement directly. IsAncestorOf checks if self, or in the case of line 10, CurrentMap, is an ascending parent of the argument, or Bricktops, on the hierarchy. Because you're referencing game.ReplicatedStorage.Maps.Bricktops
rather than a global variable for the Bricktops object, it is impossible for the if statement to pass.
TLDR; give Bricktops a reference in the global environment and pass that instead of game.ReplicatedStorage.Maps.Bricktops
. I.E.;
local Bricktops = game.ReplicatedStorage.Maps.Bricktops