Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my round script reset when LocalPlayer dies, and how can I fix it?

The script works, but it resets once someone dies. Sorry if it's messy. :P


local storage1 = game:GetService("ServerStorage")
local storage = game:GetService("ReplicatedStorage")
local text = storage:WaitForChild("Value")
local players = game.Players.LocalPlayer
local island = storage.Island

text.Changed:connect(function()
	players.PlayerGui.ScreenGui.round.Text = text.Value
end)

while true do
	game.Workspace.elevatorMusic:Play()	
	for i= 15,1,-1 do
		text.Value = "Game starts in "..i.." seconds."
		wait(1)
	end
	game.Workspace.elevatorMusic:Stop()	
	local clone = island:Clone()
	clone.Parent = workspace
	game.Workspace.evangelion1:Play()
	if players ~= nil then 
		
   			players.Character.Torso.CFrame = game.Workspace.Island["tp1"].CFrame + Vector3.new(0,5,0)
		end

	for i= 60,1,-1 do
		text.Value = "Game ends in "..i.." seconds."
		wait(1)
	end
	if players ~= nil then 
	
   			players.Character.Torso.CFrame = game.Workspace.Spawn.thespawn.CFrame + Vector3.new(0,5,0)
	   
	end

		game.Workspace.Island:Destroy()
		game.Workspace.evangelion1:Stop()
		game.Workspace.caramel.TimePosition = 50		
		text.Value = "You win!"
		game.Workspace.caramel:Play()
		for i=11,1,-1 do
	players.PlayerGui.ScreenGui.round.TextColor3 = Color3.new(255,255,0)
	wait(.5)
	players.PlayerGui.ScreenGui.round.TextColor3 = Color3.new(255,0,0)
	wait(.5)
end
		game.Workspace.caramel:Stop()
		players.PlayerGui.ScreenGui.round.TextColor3 = Color3.new(255,255,255)	
end

2 comments

0

Is this round script in a local script?

0

You should make this a regular script, and check how many players there are, not if the player is there

1 answer

✓ Accepted answer

I don't know if this is the problem, but you should probably not use a local script for this, you should use a regular script for game handlers like these. Using LocalPlayer in these kinds of scripts gets really buggy.

You should first replace the LocalPlayer stuff, as you will be switching to a regular script, or a Server Script. First get the service you will be using, which will be the Player service. You can access services with the game:GetService() function.

local players = game:GetService("Players")

Inside of you loop, you should define the table of all players (If it isn't looped it won't update). You can get the players from the player service using the Players:GetPlayers() function

local players = game:GetService("Players")

while true do 
	--Your other stuff
	local contestants = players:GetPlayers()
end

Then you would need to use a for loop to do the same things for all of the players.

local players = game:GetService("Players")

while true do 
	--Your other stuff
	local contestants = players:GetPlayers()
	for _, player in pairs(contestants) do
		players.Character.Torso.CFrame = game.Workspace.Island["tp1"].CFrame + Vector3.new(0,5,0)
end

Do this same thing for the thespawn part.

I hope this worked or helped

This discussion is preserved as it was. New answers, comments, and votes are closed.