Trying to make my own versions of DTI and wrote a script, but sometimes it doesn’t update the text or the camera.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local starsDataStore = DataStoreService:GetDataStore("PlayerStarsDataStore")
-- RemoteEvents
local UpdateCountdown = Instance.new("RemoteEvent", ReplicatedStorage)
UpdateCountdown.Name = "UpdateCountdown"
local TeleportEvent = Instance.new("RemoteEvent", ReplicatedStorage)
TeleportEvent.Name = "TeleportPlayers"
local SubmitVote = Instance.new("RemoteEvent", ReplicatedStorage)
SubmitVote.Name = "SubmitVote"
local SetExternalCamera = Instance.new("RemoteEvent", ReplicatedStorage)
SetExternalCamera.Name = "SetExternalCamera"
local DisableControls = Instance.new("RemoteEvent", ReplicatedStorage)
DisableControls.Name = "DisableControls"
-- Variables
local lobbyTime = 10 -- Lobby time in seconds
local gameTime = 5 -- Time for each player to walk the runway
local votingTime = 15 -- Voting duration
local themes = { "goth", "beach", "futuristic", "retro", "nature", "formal", "sporty", "fantasy" }
local playerVotes = {}
local function resetVotes()
playerVotes = {}
for _, player in pairs(Players:GetPlayers()) do
playerVotes[player.UserId] = { score = 0, votes = 0 }
end
end
local function loadPlayerStars(player)
local playerKey = "Player_" .. player.UserId
local success, stars = pcall(function()
return starsDataStore:GetAsync(playerKey)
end)
if success and stars then
player:SetAttribute("Stars", stars)
else
player:SetAttribute("Stars", 0)
end
end
local function savePlayerStars(player)
local playerKey = "Player_" .. player.UserId
local stars = player:GetAttribute("Stars")
local success, errorMessage = pcall(function()
starsDataStore:SetAsync(playerKey, stars)
end)
if not success then
warn("Failed to save stars for player " .. player.Name .. ": " .. errorMessage)
end
end
-- Helper to teleport players to a specific location
local function teleportPlayers(location)
for _, player in pairs(Players:GetPlayers()) do
if player.Character and player.Character.PrimaryPart then
print("Teleporting player " .. player.Name .. " to location: " .. location.Name)
player.Character:SetPrimaryPartCFrame(location.CFrame)
end
end
end
local function setCameraToPart(camera, part)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
end
local function startVoting()
local votingSpawn = workspace:WaitForChild("VotingSpawn")
teleportPlayers(votingSpawn)
for _, player in pairs(Players:GetPlayers()) do
print("Setting camera to voting spawn for player " .. player.Name)
SetExternalCamera:FireClient(player) -- Tell client to use fixed camera
local camera = workspace.CurrentCamera
setCameraToPart(camera, votingSpawn)
end
end
local function walkRunway(player)
local runwayStart = workspace:WaitForChild("RunwayStart")
local runwayEnd = workspace:WaitForChild("RunwayEnd")
local runwayExit = workspace:WaitForChild("RunwayExit")
DisableControls:FireClient(player, true)
local character = player.Character
local humanoid = character:FindFirstChildOfClass("Humanoid")
-- Move player to the start of the runway
print("Moving player " .. player.Name .. " to runway start")
character:SetPrimaryPartCFrame(runwayStart.CFrame)
task.wait(1)
-- Move player along the runway
humanoid:MoveTo(runwayEnd.Position)
humanoid.MoveToFinished:Wait()
-- Player reaches the end
print("Player " .. player.Name .. " reached the runway end.")
task.wait(2) -- Wait for a bit
humanoid:MoveTo(runwayExit.Position)
humanoid.MoveToFinished:Wait()
print("Player " .. player.Name .. " exited the runway.")
DisableControls:FireClient(player, false)
end
-- Voting system handler
SubmitVote.OnServerEvent:Connect(function(player, stars)
if playerVotes[player.UserId] then
playerVotes[player.UserId].score = stars
print("Player " .. player.Name .. " voted " .. stars .. " stars.")
end
end)
-- Load stars when player joins
Players.PlayerAdded:Connect(function(player)
loadPlayerStars(player)
player.AncestryChanged:Connect(function(_, parent)
if not parent then
savePlayerStars(player)
end
end)
end)
-- Game loop
while true do
wait(1)
-- Lobby countdown
for i = lobbyTime, 1, -1 do
UpdateCountdown:FireAllClients("Lobby Time Left: " .. i .. " seconds")
wait(1)
end
-- Game starts
local theme = themes[math.random(1, #themes)]
UpdateCountdown:FireAllClients("Game started! Theme: " .. theme .. ". Time left: " .. gameTime .. " seconds")
teleportPlayers(workspace:WaitForChild("GameSpawn"))
-- Game countdown
for i = gameTime, 1, -1 do
UpdateCountdown:FireAllClients("Game Time Left: " .. i .. " seconds")
wait(1)
end
-- Start runway voting
resetVotes()
startVoting()
for _, player in pairs(Players:GetPlayers()) do
UpdateCountdown:FireClient(player, "Now voting for: " .. player.Name .. "!")
walkRunway(player)
end
-- Enable Voting UI for all players at once
for _, otherPlayer in pairs(Players:GetPlayers()) do
otherPlayer.PlayerGui.VotingUI.Enabled = true
end
-- Wait for voting to finish
wait(votingTime)
-- Collect votes here before disabling UI
for _, player in pairs(Players:GetPlayers()) do
local lastVote = playerVotes[player.UserId] and playerVotes[player.UserId].score or 0
print("Player " .. player.Name .. " last voted " .. lastVote .. " stars.")
end
-- Disable Voting UI for all players
for _, otherPlayer in pairs(Players:GetPlayers()) do
otherPlayer.PlayerGui.VotingUI.Enabled = false
end
-- Calculate and announce results
local sortedPlayers = {}
for userId, data in pairs(playerVotes) do
table.insert(sortedPlayers, { userId = userId, score = data.score })
end
table.sort(sortedPlayers, function(a, b) return a.score > b.score end)
local winnerMsg = "Results:\n"
for i = 1, math.min(3, #sortedPlayers) do
local playerName = Players:GetNameFromUserIdAsync(sortedPlayers[i].userId)
winnerMsg = winnerMsg .. i .. ". " .. playerName .. " with " .. sortedPlayers[i].score .. " stars!\n"
end
UpdateCountdown:FireAllClients(winnerMsg)
-- Pause before resetting
wait(5)
-- Reset for the next round
resetVotes()
end