.script only works once, after it runs it just goes to sleep

the script:

local blackscreen = game.Players.LocalPlayer.PlayerGui:WaitForChild("BlackScreen").Frame
local ts = game:GetService("TweenService")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

char:WaitForChild("Humanoid").Died:Connect(function()
	ts:Create(blackscreen, TweenInfo.new(3, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 0}):Play()
	wait(4)
	game:GetService("Lighting")["ANOTHER BLUR"].Enabled = true
	ts:Create(blackscreen, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
	wait(1.5)
	char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	game:GetService("Lighting")["ANOTHER BLUR"].Enabled = false
	
end)

first time I die it works fine
second+ times I die it won’t function
how to I mitigate that so it will always work when I die?

Probably because you assigned char two times. So when they die, it has probably already loaded and your just infinitely waiting for the char to load again but it already has. Idk may be not the case but, considering trying it out. All in all, if it works, your code should be like this:

local blackscreen = game.Players.LocalPlayer.PlayerGui:WaitForChild("BlackScreen").Frame
local ts = game:GetService("TweenService")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

char:WaitForChild("Humanoid").Died:Connect(function()
	ts:Create(blackscreen, TweenInfo.new(3, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 0}):Play()
	wait(4)
	game:GetService("Lighting")["ANOTHER BLUR"].Enabled = true
	ts:Create(blackscreen, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
	wait(1.5)
	---char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
--remove this ^^^
	game:GetService("Lighting")["ANOTHER BLUR"].Enabled = false
	
end)

edit: You can also use a more reliable way using health changed signal (have not tested this out. lmk if it errors):

local blackscreen = game.Players.LocalPlayer.PlayerGui:WaitForChild("BlackScreen").Frame
local ts = game:GetService("TweenService")
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

char:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function(health)
	if health == 0 then
		ts:Create(blackscreen, TweenInfo.new(3, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 0}):Play()
		wait(4)
		game:GetService("Lighting")["ANOTHER BLUR"].Enabled = true
	elseif health == 100 then
		ts:Create(blackscreen, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
		wait(1.5)
		char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
		game:GetService("Lighting")["ANOTHER BLUR"].Enabled = false
	end
end)

You never handle a respawned character

local blackscreen = game.Players.LocalPlayer.PlayerGui:WaitForChild("BlackScreen").Frame
local ts = game:GetService("TweenService")

function handle()
	local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

	char:WaitForChild("Humanoid").Died:Connect(function()
		ts:Create(blackscreen, TweenInfo.new(3, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 0}):Play()
		wait(4)
		game:GetService("Lighting")["ANOTHER BLUR"].Enabled = true
		ts:Create(blackscreen, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
		wait(1.5)
		---char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
--remove this ^^^
		game:GetService("Lighting")["ANOTHER BLUR"].Enabled = false
		handle()
	end)
end

handle()

Because you have a new Charachter when u die, do this:

local blackscreen = game.Players.LocalPlayer.PlayerGui:WaitForChild("BlackScreen").Frame
local ts = game:GetService("TweenService")

local player = game:GetService("Players").LocalPlayer

player.CharacterAdded:Connect(function(char)
char:WaitForChild("Humanoid").Died:Connect(function()
	ts:Create(blackscreen, TweenInfo.new(3, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 0}):Play()
	wait(4)
	game:GetService("Lighting")["ANOTHER BLUR"].Enabled = true
	ts:Create(blackscreen, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {BackgroundTransparency = 1}):Play()
	wait(1.5)
	game:GetService("Lighting")["ANOTHER BLUR"].Enabled = false
	
end)
end)

Not sure if this works but, why the heck are you using 3 functions in 1 playeradded function? Seems repititive to me but, if it works, it works.

If u want to use CharacterAdded, then u need to use PlayerAdded. If u want to use .Died:Connect for your CharacterAdded Event, then u need to use .Died:Connect.

The CharacterAdded function is enough, you don’t have to use PlayerAdded function inside a local script

I didnt saw that this is a Localscript

For one, you use local player, which completely removes the need of using the PlayerAdded, since this should be a local script and not a server script.

Wouldn’t recommend handling a player’s UI within a server script or handling lighting within a server script

chill yall you can send those via DMs

2 Likes

I did it already, i already said i dont see that this is in Client, and i dont wrote and improve that, i just wrote CharacterAdded so his Script works

Thats a Localscript, and handling Lighting can be done in Server or Client there is no recommending, on Server if it should be for all Players or in Client if its should be for One Player, Client will not be replace to Server for Lighting anyways

local plr = game.Players.LocalPlayer

plr.CharacterAdded:Connect(function(char)
--- function
end)

oh and another note, this script also has the same problem, whenever a gun fires in full-auto the character is supposed to walk, however also does it once and goes to sleep

game.ReplicatedStorage.ShootEvent.OnServerEvent:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	player.PlayerGui["Realism Mod"].Sprint.Enabled = false
	character:WaitForChild("Humanoid").WalkSpeed = 10
	wait(0.01)
	player.PlayerGui["Realism Mod"].Sprint.Enabled = true
end)

Are there any errors in the output?

no, not any

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.