tell me, what position does your template have, if not {0,0},{0,0}?
also i rewrite your script:
--services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local plrTeam = player.Team
local parent = script.Parent -- RENAME
local SCORE_BOARD_TAG = "ScoreBoard"
local leftPosition = UDim2.new({0.121, 0},{0.036, 0})
local rightPosition = UDim2.new({0.777, 0},{0.036, 0})
local leftUnseenPosition = UDim2.new({0.121, 0},{-3, 0})
local rightUnseenPosition = UDim2.new({0.777, 0},{-3, 0})
local values = ReplicatedStorage.Values
local events = ReplicatedStorage.Events
local updateMinigameEvent = events.UpdateMinigameEvent
local updateHighestScoreEvent = events.UpdateCurrentHighestScoreEvent
local scoreTable = {
["Blue"] = {[SCORE_BOARD_TAG] = parent.Blue, ["Value"] = values["Blue Team Score"]},
["Red"] = {[SCORE_BOARD_TAG] = parent.Red, ["Value"] = values["Red Team Score"]}
}
local updateScoreConnection
local shownHighestScorer
local changeConnections = {}
for i, scoreBoard in CollectionService:GetTagged(SCORE_BOARD_TAG) do
scoreBoard.Position = leftUnseenPosition
scoreBoard.Visible = true
end
local function createScoreBoard(plr)
local scoreValue = values:FindFirstChild(plr.Name .. " Score")
local targetPosition = (plr == player) and rightUnseenPosition or leftUnseenPosition
local scoreTemplate = parent.Template
local scoreBoardClone = scoreTemplate:Clone()
scoreBoardClone.Parent = script.Parent
scoreBoardClone.Name = plr.Name
scoreBoardClone.NameLabel.Text = plr.DisplayName
scoreBoardClone.ScoreLabel.Text = scoreValue.Value
scoreBoardClone.Position = targetPosition
scoreBoardClone.Visible = true
scoreTable[plr] = {
[SCORE_BOARD_TAG] = scoreBoardClone,
["Value"] = scoreValue
}
print(scoreBoardClone)
print(scoreBoardClone.Position)
end
local function updateScores(plr)
local tableForPlr = scoreTable[plr]
changeConnections[plr] = tableForPlr["Value"].Changed:Connect(function(value)
tableForPlr[SCORE_BOARD_TAG].ScoreLabel.Text = value
end)
end
local function removeScoreBoard(plr)
if changeConnections[plr] then
changeConnections[plr]:Disconnect()
changeConnections[plr] = nil
end
local board = scoreTable[plr][SCORE_BOARD_TAG]
board:Destroy()
scoreTable[plr] = nil
end
local function ShowScoreBoard(show, direction, scoreboard)
local targetPosition = (direction == "Right") and (show and rightPosition or rightUnseenPosition) or (show and leftPosition or leftUnseenPosition)
scoreboard.Position = targetPosition
print(scoreboard.Position)
end
createScoreBoard(player)
ShowScoreBoard(false, "Right", scoreTable[player].ScoreBoard)
for _, team in {player, "Blue", "Red"} do
task.spawn(function()
updateScores(team)
end)
end
task.spawn(function()
Players.PlayerAdded:Connect(function(plr)
createScoreBoard(plr)
updateScores(plr)
end)
Players.PlayerRemoving:Connect(function(plr)
changeConnections[plr]:Disconnect()
removeScoreBoard(plr)
end)
end)
local MINIGAMES = {FFA = "FFA", TDM = "TDM"}
local function hideAllScoreboards()
for _, scoreboard in (CollectionService:GetTagged(SCORE_BOARD_TAG)) do
local scoreboardData = scoreTable[scoreboard.Name]
if scoreboardData then
local scoreboardSide = (scoreboard.Name == player.Name or scoreboard.Name == plrTeam) and "Right" or "Left"
ShowScoreBoard(false, scoreboardSide, scoreboardData[SCORE_BOARD_TAG])
end
end
end
local function handleFFA()
ShowScoreBoard(true, "Right", scoreTable[player][SCORE_BOARD_TAG])
if updateScoreConnection then updateScoreConnection:Disconnect() end
updateScoreConnection = updateHighestScoreEvent.OnClientEvent:Connect(function(highestScorer)
if shownHighestScorer == highestScorer then return end
ShowScoreBoard(false, "Left", scoreTable[shownHighestScorer][SCORE_BOARD_TAG])
ShowScoreBoard(true, "Left", scoreTable[highestScorer][SCORE_BOARD_TAG])
shownHighestScorer = highestScorer
end)
end
local function handleTDM()
local blueTeamBoard = script.Parent.Blue.Name
local redTeamBoard = script.Parent.Red.Name
local plrTeam = player.Team.Name
local leftTeamBoard = (plrTeam == blueTeamBoard) and redTeamBoard or blueTeamBoard
ShowScoreBoard(true, "Right", scoreTable[plrTeam][SCORE_BOARD_TAG])
ShowScoreBoard(true, "Left", scoreTable[leftTeamBoard][SCORE_BOARD_TAG])
end
local minigameHandlers = {
[MINIGAMES.FFA] = handleFFA,
[MINIGAMES.TDM] = handleTDM,
}
updateMinigameEvent.OnClientEvent:Connect(function(minigame)
hideAllScoreboards()
local handler = minigameHandlers[minigame]
handler()
end)