Unsure why this capture the flag system is not working?(Solved)

local moduleScript = require(game.ServerScriptService.ModuleScript)
local waitdebounce = 1
local debounce = false
local Players = game:GetService("Players")
local redclaim = false
local blueclaim = false
local claiming = false

local flag = script.Parent
local plate = script.parent.parent.TriggerPlate
local function onPartTouch(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then

		local player = Players:GetPlayerFromCharacter(partParent)
		local leaderstats = player.leaderstats
		local pointsStat = leaderstats and leaderstats:FindFirstChild("Points")
		if pointsStat and moduleScript.pointsallowed == 1 then
			if player.TeamColor.Name == "Really red" then
				wait(3)
				redclaim = true
				blueclaim = false
			elseif player.TeamColor.Name == "Really blue" then
				wait(3)
				blueclaim = true
				redclaim = false
			end
			if player.TeamColor.name == "Really red" and redclaim == true then
				while true do
					wait(1)
					flag.BrickColor = BrickColor.new("Really red")
					pointsStat = pointsStat + 1
					if blueclaim == true then break
						
					end
					if player.TeamColor.name == "Really red" and blueclaim == true then
						wait(3)
							while true do
							wait(1)
							flag.BrickColor = BrickColor.new("Really red")
							pointsStat = pointsStat + 1
							if blueclaim == true then
								break
								end
								if player.TeamColor.name == "Really blue" and blueclaim == true then
									while true do
										wait(1)
										flag.BrickColor = BrickColor.new("Really blue")
										pointsStat = pointsStat + 1
								end		if redclaim == true then
								end				break
								end
							if player.TeamColor.name == "Really blue" and redclaim == true then
								wait(3)
									while true do
										wait(1)
										flag.BrickColor = BrickColor.new("Really blue")
										pointsStat = pointsStat + 1
									end		if redclaim == true then
								end				break
							end	if player.TeamColor.name == "Really blue" and redclaim == false and blueclaim == false then
								wait(3)
								while true do
									wait(1)
									flag.BrickColor = BrickColor.new("Really blue")
									pointsStat = pointsStat + 1
								end		if redclaim == true then
							end				break
							end	if player.TeamColor.name == "Really red" and redclaim == false and blueclaim == false then
								wait(3)
								while true do
									wait(1)
									flag.BrickColor = BrickColor.new("Really red")
									pointsStat = pointsStat + 1
								end		if blueclaim == true then
							end				break
							end	if player.TeamColor.name == "Really blue" and redclaim == false and blueclaim == false then
								wait(3)
								while true do
									wait(1)
									flag.BrickColor = BrickColor.new("Really blue")
									pointsStat = pointsStat + 1
							end		if redclaim == true then
						end				break
					end
				end
			end
		end
   	 end
		end 
	end
	end 
plate.Touched:Connect(onPartTouch)

I know my code is messy, but I’m a beginner and really can’t fix that. What I’m more worried about is that this script is not working. There are 2 teams. Really red, and Really blue, and this script is placed in all the flags of the capture the flag “flags”. Please help! I’ve literally tried everything and worked really hard on this and even made a prototype system that did work, but not very well. So, simply I don’t want to have to redo everything. PS. Some variables at the top don’t matter, those are just from my previous prototypes.

6 Likes

What’s in the module script? Anything important? Any errors?
If there’s no errors you can test what if statement isn’t working by putting prints after all of them and testing where it stops printing.

1 Like

The module script was actually from a previous prototype I made with this system. It isn’t used anymore and I just forgot to remove the variables, and no, there are no errors anywhere in the code, both in the module and server script.

2 Likes

My best suggestion is to again put prints after your if statements and see where it stops printing, and where it stops is where it’s not working. From there if you need more help tell me what line it stopped working at.

1 Like

I’ve tried, and still, nothing is printing. Could it be that the function isn’t being called? I did call it however on a part touch event for the trigger plate.

1 Like

Yeah the event probably isn’t being called, try replacing

local plate = script.parent.parent.TriggerPlate

with

local plate = script.Parent.Parent.TriggerPlate
2 Likes

Thank you so much! It isn’t working, but at least it’s acknowledging the script claiming. Now I can just fix up the code.

1 Like

Haha glad I could help.
I’m surprised it didn’t error that “parent” isn’t a valid member of script. Those capital letters always cause trouble.

Okay, this is weird. Now it’s literally not printing anything again. No idea what is happening.

1 Like

send the updated script, im not at my pc rn but ill try to help anyway, and no printing includes no errors right?

1 Like

Oh, actually I fixed it, just a capitalization error with a variable. Still the script itself is not working. Sorry for bugging you haha, if you have any idea why it’s not working that would be amazing but no need, you’ve already helped enough

local Players = game:GetService("Players")
local redclaim = false
local blueclaim = false

local flag = script.Parent
local Plate = script.Parent.Parent.TriggerPlate
local function onPartTouch(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then

		local player = Players:GetPlayerFromCharacter(partParent)
		local leaderstats = player.leaderstats
		local pointsStat = leaderstats and leaderstats:FindFirstChild("Points")
			if player.TeamColor.Name == "Really red" then
				wait(3)
				redclaim = true
			blueclaim = false
			print ("redclaim = true")
			elseif player.TeamColor.Name == "Really blue" then
				wait(3)
				blueclaim = true
			redclaim = false
			print ("blueclaim = true")
			end
		if player.TeamColor.name == "Really red" and redclaim == true then
			print("Red claimed red")
				while true do
					wait(1)
					flag.BrickColor = BrickColor.new("Really red")
					pointsStat = pointsStat + 1
				if blueclaim == true then 
					print("blueclaim == true")
					break
					end
					if player.TeamColor.name == "Really red" and blueclaim == true then
					wait(3)
					print("Red claimed blue")
							while true do
							wait(1)
							flag.BrickColor = BrickColor.new("Really red")
							pointsStat = pointsStat + 1
						if blueclaim == true then
							print("blueclaim == true")
								break
								end
						if player.TeamColor.name == "Really blue" and blueclaim == true then
							print("Blue claimed blue")
									while true do
										wait(1)
										flag.BrickColor = BrickColor.new("Really blue")
										pointsStat = pointsStat + 1
							end		if redclaim == true then
								print("redclaim == true")
								end				break
								end
							if player.TeamColor.name == "Really blue" and redclaim == true then
							wait(3)
							print("Blue claimed red")
									while true do
										wait(1)
										flag.BrickColor = BrickColor.new("Really blue")
										pointsStat = pointsStat + 1
							end		if redclaim == true then
								print("redclaim == true")
								end				break
							end	if player.TeamColor.name == "Really blue" and redclaim == false and blueclaim == false then
							wait(3)
							print("Blue claimed neutral")
								while true do
									wait(1)
									flag.BrickColor = BrickColor.new("Really blue")
									pointsStat = pointsStat + 1
							end		if redclaim == true then
								print("redclaim == true")
							end				break
							end	if player.TeamColor.name == "Really red" and redclaim == false and blueclaim == false then
							wait(3)
							print("Red claimed neutral")
								while true do
									wait(1)
									flag.BrickColor = BrickColor.new("Really red")
									pointsStat = pointsStat + 1
							end		if blueclaim == true then
								print("blue == true")
							end				break
							end	
					end
				end
			end
		end
   	 end
		end 
plate.Touched:Connect(onPartTouch)

Ah, like I said always the capitals, well are you getting any errors now that it’s working again?

Nope. Completely clean but just doesn’t go farther than the print ("blueclaim == true") or print ("redclaim == true"). It should change the BrickColor of the flag and give 1 point every second till another team claims it.

try changing

if player.TeamColor.name == "Really red" and redclaim == true then

to

if player.TeamColor.Name == "Really red" and redclaim == true then

and do the same for

if player.TeamColor.name == "Really blue" and blueclaim == true then

also gonna be afk for a bit

2 Likes

Currently changing it. Not sure if it’s working. EDIT: It’s working. The team color was actually the problem. (as well as the .Name) Also, I forgot to add . Value at the end. Gotta add debounce now haha. Thank you so much! You are a lifesaver.

2 Likes

of course of course, so issue fully resolved?

2 Likes

Yep. Fully working! Thank you so much again!

1 Like

alright good to hear, you said your a beginner to scripting? if you need any help whatsoever don’t be afraid to dm me, I actually really like teaching people stuff haha

Yeah, I’m quite new. I don’t really know much apart from like the touched events, variables and functions lol, maybe a bit of modular scripts but not very good with them. Thank you for the offer! I’ll dm you 100% if I have a concern or question

1 Like