So, as the tittle says, i am trying to apply a script into multiple parts for a capture points system, however, i dont know why this is happening, the script is applyied into just one part, i have tryied some possible solutions but no one worked.
local module = {}
function module.GameMode1()
local bluesInPoint = {}
local redsInPoint = {}
local redPoints = 1
local bluePoints = 5
local blueTeam = game.Teams.BlueTeam
local redTeam = game.Teams.RedTeam
local points
for i,v in pairs(workspace.Map1:GetChildren()) do
points = v
end
points.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild("Humanoid") then
if player.Team == blueTeam then
if table.find(bluesInPoint,player.UserId) then
table.insert(bluesInPoint,player.UserId)
end
elseif player.Team == redTeam then
if not table.find(redsInPoint,player.UserId) then
table.insert(redsInPoint,player.UserId)
end
end
end
end)
points.TouchEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild("Humanoid") then
if player.Team == blueTeam then
local index = table.find(bluesInPoint,player.UserId)
if index then
table.remove(bluesInPoint,table.find(bluesInPoint,player.UserId))
end
elseif player.Team == redTeam then
local index = table.find(redsInPoint,player.UserId)
if index then
table.remove(redsInPoint,table.find(redsInPoint,player.UserId))
end
end
end
end)
task.spawn(function()
while true do
local percentValue = points.Part.Part.percentValue
local percentText = points.Part.Part.SurfaceGui.percent
if #redsInPoint > #bluesInPoint then
local points = (#redsInPoint - #bluesInPoint)
percentValue.Value -= points
end
if percentValue.Value < 0 then
percentValue.Value = 0
end
if #bluesInPoint > #redsInPoint then
local points = (#bluesInPoint - #redsInPoint)
percentValue.Value += points
end
if percentValue.Value > 100 then
percentValue.Value = 100
end
percentText.Text = tostring(percentValue.Value)
task.wait(2)
end
end)
while task.wait() do
points.Part.countBlue.Value = #bluesInPoint
points.Part.SurfaceGui.blueCount.Text = points.Part.countBlue.Value
points.Part.CountRed.Value = #redsInPoint
points.Part.SurfaceGui.redCount.Text = points.Part.CountRed.Value
end
end
return module
the local points is just one point, and all of them are identical.
here you loop through the entire map. then at every single index, you change points to a different instance. so your just going thrhough, changed it, and then at the end it takes the value of whatever the last thing in the table was.
basically, points is just 1 part. did you already know that? or are you trying to make it a table of all the points?
Yeah? Your code shows that you are using 1 point, the code I gave you allows you to loop through the children of Map1 (points) so that it can apply the touch events to all of them.
You also need to make sure that there isn’t only 1 child of Map1.
Also, here you put “if a player user id is not in redsinpoint table then add it” but for the bluesinpoint, you are adding it to the table if it’s already in the table… You forgot to add a “not”
Also, this while loop should be somewhere else, preferably in the code which calls/requires the module, otherwise it won’t return at all, you haven’t even added a condition to the while loop so it will never return.