I’m having a problem with how much "end"s I need
Also if you could can you not change my code to much
game.Players.PlayerAdded:Connect(function(plr)
local Part = game:GetService("ServerStorage").Part:Clone()
Part.Parent = workspace
Part.Name = plr.Name
local pn = Part.Name
local coins = Part.Coins.Value
local max = Part.MaxCoins.Value
Part.BillboardGui.TextLabel.Text = coins.."/"..max
Part.SurfaceGui.TextLabel.Text = pn
local plrs = game:GetService("Players"):GetChildren()
local pa = #plrs
if pa == 1 then
Part.CFrame = workspace.S1.CFrame
else if pa == 2 then
Part.CFrame = workspace.S2.CFrame
else if pa == 3 then
Part.CFrame = workspace.S3.CFrame
else if pa == 4 then
Part.CFrame = workspace.S4.CFrame
else if pa == 5 then
Part.CFrame = workspace.S5.CFrame
else if pa == 6 then
Part.CFrame = workspace.S.CFrame
end
end
while wait(1) do
if coins < max or not coins == max then
coins += 1
Part.BillboardGui.TextLabel.Text = coins.."/"..max
end
Part.ClickDetector.MouseClick:Connect(function(plr)
if plr.Name == Part.SurfaceGui.TextLabel.Text then
plr.leaderstats.Coins.Value += coins
coins = 0
Part.BillboardGui.TextLabel.Text = coins.."/"..max
end
end)
end)
local Part = game:GetService("ServerStorage").Part:Clone()
local pn = Part.Name
local coins = Part.Coins.Value
local max = Part.MaxCoins.Value
local plrs = game:GetService("Players"):GetChildren()
local pa = #plrs
game.Players.PlayerAdded:Connect(function(plr)
Part.Parent = workspace
Part.Name = plr.Name
Part.BillboardGui.TextLabel.Text = coins.."/"..max
Part.SurfaceGui.TextLabel.Text = pn
if pa == 1 then
Part.CFrame = workspace.S1.CFrame
elseif pa == 2 then
Part.CFrame = workspace.S2.CFrame
elseif pa == 3 then
Part.CFrame = workspace.S3.CFrame
elseif pa == 4 then
Part.CFrame = workspace.S4.CFrame
elseif pa == 5 then
Part.CFrame = workspace.S5.CFrame
elseif pa == 6 then
Part.CFrame = workspace.S.CFrame
end
end)
while wait(1) do
if coins < max or not coins == max then
coins += 1
Part.BillboardGui.TextLabel.Text = coins.."/"..max
end
end
Part.ClickDetector.MouseClick:Connect(function(plr)
if plr.Name == Part.SurfaceGui.TextLabel.Text then
plr.leaderstats.Coins.Value += coins
coins = 0
Part.BillboardGui.TextLabel.Text = coins.."/"..max
end
end)
This should work, also I swapped out the repetitive part of code for one line
game.Players.PlayerAdded:Connect(function(plr)
local playerName = plr.Name
local Part = game:GetService("ServerStorage").Part:Clone()
Part.Parent = workspace
Part.Name = plr.Name
local coins = Part.Coins.Value
local max = Part.MaxCoins.Value
Part.BillboardGui.TextLabel.Text = coins.."/"..max
Part.SurfaceGui.TextLabel.Text = playerName
local plrs = game:GetService("Players"):GetPlayers()
local playerAmount = #plrs
Part.CFrame = workspace["S" ..tostring(playerAmount)].CFrame
while task.wait(1) do
if coins < max or not coins == max then
coins += 1
Part.BillboardGui.TextLabel.Text = coins.."/"..max
end
Part.ClickDetector.MouseClick:Connect(function(clickPlayer)
if clickPlayer.Name == Part.SurfaceGui.TextLabel.Text then
plr.leaderstats.Coins.Value += coins
coins = 0
Part.BillboardGui.TextLabel.Text = coins.."/"..max
end
end)
end
end)