Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

This will not work and there is no error popping up in output, what is the problem?

Hello, I am attempting to make a Capture The Flag (CTF) game. My script works although, when I add a team check the scripts breaks but there is no error, no idea what the issue is.

Here is my code -

local Debounce = false
local IsCarryingFlagR = nil

game.Workspace.FlagStandR.Part1.Touched:Connect(function(Player)
	local Character = Player.Parent
	local PlrFilePlayer = game.Players:GetPlayerFromCharacter(Player.Parent)
	if Character then
		if IsCarryingFlagR == nil or IsCarryingFlagR == false then
			if PlrFilePlayer.TeamColor == BrickColor.new("Cyan") then
				if Debounce == false then
					Debounce = true

					local Humanoid = Character:FindFirstChild("Humanoid")
					local FlagAccessory = game.ServerStorage.RedFlagAccessory:Clone()
					FlagAccessory.Parent = Player.Parent

					IsCarryingFlagR = true

					game.Workspace.RedFlagPart:Destroy()

					Humanoid.Died:Connect(function()
						local NewRedFlagPart = game.ServerStorage.RedFlagPart:Clone()
						NewRedFlagPart.Name = "RedFlagPart"
						NewRedFlagPart.Parent = game.Workspace
						IsCarryingFlagR = false
					end)

					wait(5)

					Debounce = false
				end
			end
		end
	end
end)

This is where it breaks -

if PlrFilePlayer.TeamColor == BrickColor.new("Cyan") then

1 comment

0

also, tbh replicated storage is a better place to put stuffs to be cloned. Make a folder name Flags, and put the flags there.

1 answer

Make sure to put PlayerAdded function

local Debounce = false
local IsCarryingFlagR = nil

game.Players.PlayerAdded:Connect(function(Player)
	game.Workspace.FlagStandR.Part1.Touched:Connect(function(hit)
		-- your script here
	end)
end)

and also the error line I think it should go like this

if Player.TeamColor == BrickColor.new("Cyan") then

if it doesn't work, dm me on discord: Blue Duck#9891

1 comment

0

It’s very inefficient for that event to run everytime a player joins, my error line SHOULD work fine, and I have already tried that.

This discussion is preserved as it was. New answers, comments, and votes are closed.