Morning guys, so i got this problem while doing my capturing flag mechanic, and its that, or my script isnt detecting the StringValue that is in the character of every player with its value of the player team or i am doing something wrong with my if statements, can you help me out? Like the mechanic is basically checks if the current flag point is captured or not, and checks if there is a player who is not from the same team as the Current flag, and also checks for defenders who stop the capturing process until the players who are not from the current flag team and viceversa. The issue here is that the capturing process stills goes on having a player which team is not the same as the other one, so how can this be fixed? i share to you my scripts and some evidence.
See, when a opposite team player enters the zone it stills capturing and i dont want that, i want it to stop until, either a Allies or a Axis team leaves the zone and then continue capture.
robloxapp-20201031-0845243.wmv (247.6 KB)
My script.
local max_radius_size = 20
local part = game.Workspace.Part
local CurrentTeam
local capturing = game.ReplicatedStorage.Capturing
local ileft = game.ReplicatedStorage.ILeft
local CanCapture = game.ReplicatedStorage.CapturingInside.Value
local capturers = 0
local captureProgressValue = game.ReplicatedStorage.CaptureProgress.Value
local defenders = 0
local max_value = 1
while true do
wait()
for i, playersCircle in pairs(game.Players:GetPlayers()) do
local char = playersCircle.Character or playersCircle.CharacterAdded:Wait()
local PlayerTeam = char:WaitForChild("TeamValue").Value
local distance = (char.HumanoidRootPart.Position - part.Position).Magnitude
if distance < max_radius_size then -- CHECKS IF PLAYERS IS WITHIN CAPTURE RADIUS
CanCapture = true -- MAKE THIS VARIABLE TRUE TO MAKE PLAYER ABLE TO CAP
capturing:FireClient( playersCircle,CurrentTeam, captureProgressValue)
if CurrentTeam == nil and CanCapture then -- WE SEE IF THE FLAG HAS NO OWNER
if PlayerTeam ~= PlayerTeam then
CanCapture = false
elseif PlayerTeam == PlayerTeam then
CanCapture = true
end
if CanCapture then
captureProgressValue = math.clamp(captureProgressValue + 0.05, 0,1)
wait(1)
print("contrarios")
if captureProgressValue == max_value then
CurrentTeam = PlayerTeam
end
end
end
else
CanCapture = false
end -- first If statement
end -- for i, v in pairs() loop
end -- while true do line
Thanks in advance!!!