You can write your topic however you want, but you need to answer these questions:
-
Trying to add a crown to a player it works but only for the first player that joins
-
**
** -
Adding WaitForChild
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)
local leaderstats = player:WaitForChild("leaderstats")
local playerWins = leaderstats:WaitForChild("Wins")
playerWins.Changed:Connect(function()
checkWins(player, playerWins.Value)
end)
end
Players.PlayerAdded:Connect(setupPlayer)
while true do
wait(1)
for _, player in pairs(Players:GetPlayers()) do
setupPlayer(player)
end
end
Anyone know how to fix it please and thanks.