Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Leaderboard script will duplicated Players on leaderboard for some reason?[SOLVED]

Asked by 2 months ago
Edited 2 months ago

For the first Player It will not duplicated players sometimes but players after it will duplicate some players

 local AddLeaderboard = game:GetService("ReplicatedStorage"):WaitForChild("AddLeaderBoard")

local PlayerName = script:WaitForChild("PlayerName")



local Player = game:GetService("Players").LocalPlayer



function getLastPlayerOnBoard()

local Total = #script.Parent.Names:GetChildren()

for i,v in pairs(script.Parent.Names:GetChildren()) do

if i == Total then

return v

end

end

end



function getPlayerFrameNumber(PlayerName)

for i,v in pairs(script.Parent.Names:GetChildren()) do

if v.Txt.Text == PlayerName then

return i

end

end

end



function getAllAfterPlayer(FrameNumber)

local Frames = {}

for i,v in pairs(script.Parent.Names:GetChildren()) do

if i >= FrameNumber then

table.insert(Frames,v)

end

end

return Frames

end



function getPlayerFrameGui(PlayersName)

for i,v in pairs(script.Parent.Names:GetChildren()) do

if v.Txt.Text == PlayersName then

return v

end

end

end



AddLeaderboard.OnClientEvent:Connect(function(Key,Player)

if Key == "Join" then

if #script.Parent.Names:GetChildren() > 0 then

local Last = getLastPlayerOnBoard()

local ClonePlayerName = PlayerName:Clone()

ClonePlayerName.Txt.Text = Player.Name

ClonePlayerName.Wxt.Text = 0

ClonePlayerName.Parent = script.Parent.Names

ClonePlayerName.Position = Last.Position + UDim2.new(0,0,0.085,0)

else

local Last = getLastPlayerOnBoard()

local ClonePlayerName = PlayerName:Clone()

ClonePlayerName.Txt.Text = Player.Name

ClonePlayerName.Wxt.Text = 0

ClonePlayerName.Parent = script.Parent.Names

end

elseif Key == "Leave" then

local Frame = getPlayerFrameGui(Player.Name)

local FrameNum = getPlayerFrameNumber(Player.Name)

local OtherFramesAfter = getAllAfterPlayer(FrameNum+1)

if Frame then

Frame:TweenPosition(Frame.Position+UDim2.new(1,0,0,0),"Out","Bounce",1,true)

wait(1)

Frame:Destroy()

end

for i,v in pairs(OtherFramesAfter) do

local NeededPosition = v.Position - UDim2.new(0,0,0.085,0)

v:TweenPosition(NeededPosition,"In","Linear",0.5,true)

end

end

end)



function CheckIfHasFrame(Player)

for i,v in pairs(script.Parent.Names:GetChildren()) do

if v.Txt.Text == Player.Name then

return true

end

end

end







Player.CharacterAdded:Connect(function()

if #script.Parent.Names:GetChildren() < #game:GetService("Players"):GetPlayers() then

for i,v in pairs(game:GetService("Players"):GetPlayers()) do

local HasFrame = CheckIfHasFrame(v)

if not HasFrame then

if #script.Parent.Names:GetChildren() > 0 then

local Last = getLastPlayerOnBoard()

local ClonePlayerName = PlayerName:Clone()

ClonePlayerName.Txt.Text = v.Name

ClonePlayerName.Wxt.Text = 0

ClonePlayerName.Parent = script.Parent.Names

ClonePlayerName.Position = Last.Position + UDim2.new(0,0,0.085,0)

else

local Last = getLastPlayerOnBoard()

local ClonePlayerName = PlayerName:Clone()

ClonePlayerName.Txt.Text = v.Name

ClonePlayerName.Wxt.Text = 0

ClonePlayerName.Parent = script.Parent.Names

end

end

end

end

end)

GIF of the gui: First Few Players Last Few Players

0
Indent your code goddamn it incapaxx 3107 — 2mo
0
^ The new editor ruins the indention TheGreenSuperman 75 — 2mo

Answer this question