-
Trying to give a crown to a player when they join
-
It gives the crown to the first player that joins but when a 2nd joins it stops working
-
I have looked on the Developer Hub have not found anything
local Players = game:GetService("Players")
local function checkWins(player,winNumber)
if winNumber <= 9 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown1:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 19 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown2:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
crown.BillboardGui.Frame.Rank.Text = winNumber
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 29 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown3:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 39 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown4:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 49 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown5:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 74 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown6:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 99 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown7:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 249 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown8:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 499 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown9:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
elseif winNumber <= 1000 then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local crown = game.ServerStorage.Crown10:Clone()
crown.Parent = game.Workspace
if crown then
local root = crown
if root then
local rotationSpeed = 1
local distanceFromPlayer = 3
local angle = 0
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
if not crown or not root:IsDescendantOf(game) then
return
end
crown.BillboardGui.Frame.Rank.Text = winNumber
angle = (angle + rotationSpeed * deltaTime) % (2 * math.pi)
local newPosition = humanoidRootPart.Position + Vector3.new(math.cos(angle) * distanceFromPlayer, 0, math.sin(angle) * distanceFromPlayer)
root:PivotTo(CFrame.new(newPosition) * CFrame.Angles(0, math.rad(angle * 360 / (2 * math.pi)), 0))
end)
else
warn("Crown does not have a PrimaryPart or HumanoidRootPart.")
end
end
end
end
local function setupPlayer(player: Player)
local leaderstats = player:WaitForChild("leaderstats")
local playerWins = leaderstats:WaitForChild("Wins")
if (not player.Character) then
player.CharacterAppearanceLoaded:Wait()
end
playerWins.Changed:Connect(function()
checkWins(player, playerWins.Value)
end)
end
for _, player in pairs(Players:GetPlayers()) do
setupPlayer(player)
end
Players.PlayerAdded:Connect(setupPlayer)
If anyone knows please help me and thanks!