I’m trying to make it so when the game ends a frame tweens in, it works if the player hasn’t died, but if the player has died, but has respawned it says “Can only tween objects in the workspace”.
–Local script in StarterPlayerScripts
local gameEndedUI = player:WaitForChild("PlayerGui"):WaitForChild("Countdown"):WaitForChild("GameEnded")
appearUIS.OnClientEvent:Connect(function()
player.PlayerGui.Countdown.Timer.Visible = true
wait(gameConfigs.MainSettings.GameTime)
endGame:FireServer()
wait(0.5)
player.PlayerGui.Countdown.Timer.Visible = false
gameEndedUI:TweenPosition(UDim2.new(0.304, 0,0.201, 0),"In","Bounce",0.5)
if player.PlayerStats.HasWon == true then
gameEndedUI.WinLose.Text = "You Win!"
gameEndedUI.WinLose.TextColor3 = Color3.fromRGB(0,255,0)
elseif player.PlayerStats.HasWon == false then
gameEndedUI.WinLose.Text = "You Lose!"
gameEndedUI.WinLose.TextColor3 = Color3.fromRGB(255,0,0)
end
end)```
Script that fires the appearUIS event:
```lua
teleportPlayers.OnServerEvent:Connect(function(player, gameStatus)
if gameStatus == true then
UIEvent:FireAllClients()
for i, player in pairs(players:GetChildren()) do
if player.Character then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
humanoidRootPart.CFrame = CFrame.new(potentialSpawns[math.random(1, #potentialSpawns)])
player:WaitForChild("PlayerStats"):WaitForChild("InGame").Value = true
end
end
elseif gameStatus == false then
for i, player in pairs(players:GetChildren()) do
if player.Character then
local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
humanoidRootPart.CFrame = CFrame.new(mainSpawn.Position)
end
end
end
end)
endGame.OnServerEvent:Connect(function(player)
isGame.Value = false
for i, player in pairs(players:GetChildren()) do
if player.PlayerStats.InGame == true then
player.PlayerStats.HasWon.Value = true
end
end
wait(0.5)
for i, player in pairs(players:GetChildren()) do
player.PlayerStats.InGame.Value = false
end
end)```
