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.
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.
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.
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.
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.
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.
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)
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.
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.
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