Event isn't firing correctly as it's supposed to be

So I was making a revive system which has a cutscene that I implemented. But when I fired the event to the client, it wasn’t doing the cutscene as it’s supposed to be. It should be like this.


Not like this.

And here is the script.

local productFunctions = {}

productFunctions[2839291855] = function(player)
	ReplicatedStorage.Events.Revive:FireClient(player)
	player:LoadCharacter()
	player:SetAttribute("Dead", nil)
	local character = player.Character or player.CharacterAdded:Wait()
	local room = generatedRooms[currentRoomNumber]
	local cframe = room.Entrance.CFrame * CFrame.new(0,0,10) * CFrame.Angles(0, math.rad(180), 0)
	character:PivotTo(cframe)
	character:SetAttribute("MaxDoorReached", currentRoomNumber)
	return true
end

MarketplaceService.ProcessReceipt = function(info)
	local player = game.Players:GetPlayerByUserId(info.PlayerId)
	if player then
		local handler = productFunctions[info.ProductId]
		local success, result = pcall(handler, player)
		if success then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("bruh it failed", info, result)
		end
	end
	
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

Revive cutscene script.

local CameraShaker = require(game.ReplicatedStorage.Modules.Free.CameraShaker)
local magnitude = 3
local roughness = 5
local fadeInTime = 0
local fadeOutTime = 0.75
local posInfluence = 30
local rotInfluence = 100

game.ReplicatedStorage.Events.Revive.OnClientEvent:Connect(function()
	local camera = workspace.CurrentCamera
	local ts = game:GetService("TweenService")
	local model = workspace.ReviveRoom
	local startposition = model.Start.CFrame
	local goalposition = model.Goal.CFrame
	local transitiongui = game.Players.LocalPlayer.PlayerGui.TransitionGui
	local frame = transitiongui.Frame
	local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
		camera.CFrame = camera.CFrame * shakeCf
	end)
	camShake:Start()
	frame.Transparency = 0
	transitiongui.Enabled = true
	frame.BackgroundColor3 = Color3.new(0,0,0)
	ts:Create(frame, TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Transparency = 1}):Play()
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = startposition
	local tweeninfo = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.In)
	local tween = ts:Create(camera, tweeninfo, {CFrame = goalposition})
	tween:Play()
	task.wait(1.5)
	frame.BackgroundColor3 = Color3.new(1, 1, 1)
	local fade = ts:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Transparency = 0})
	fade:Play()
	fade.Completed:Wait()
	camera.CameraType = Enum.CameraType.Custom
	ts:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Transparency = 1}):Play()
	camShake:ShakeOnce(magnitude, roughness, fadeInTime, fadeOutTime, posInfluence, rotInfluence)
end)

I would add a print statement to make sure that the fading tween is running:

ts:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Transparency = 1}):Play()

In general this seems like something to debug with print statements. It seems like the event is firing if the scene runs at all, so maybe something is yielding that shouldn’t.

I updated the script a little bit. It only printed one part.

local CameraShaker = require(game.ReplicatedStorage.Modules.Free.CameraShaker)
local magnitude = 3
local roughness = 5
local fadeInTime = 0
local fadeOutTime = 0.75
local posInfluence = 30
local rotInfluence = 100

game.ReplicatedStorage.Events.Revive.OnClientEvent:Connect(function()
	local camera = workspace.CurrentCamera
	local ts = game:GetService("TweenService")
	local model = workspace.ReviveRoom
	local startposition = model.Start.CFrame
	local goalposition = model.Goal.CFrame
	local transitiongui = game.Players.LocalPlayer.PlayerGui.TransitionGui
	local frame = transitiongui.Frame
	local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
		camera.CFrame = camera.CFrame * shakeCf
	end)
	camShake:Start()
	frame.Transparency = 0
	transitiongui.Enabled = true
	frame.BackgroundColor3 = Color3.new(0,0,0)
	ts:Create(frame, TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Transparency = 1}):Play()
	print("is this thing runnin?")
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CFrame = startposition
	local tweeninfo = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.In)
	local tween = ts:Create(camera, tweeninfo, {CFrame = goalposition})
	tween:Play()
	task.wait(1.5)
	frame.BackgroundColor3 = Color3.new(1, 1, 1)
	local fade = ts:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Transparency = 0})
	fade:Play()
	fade.Completed:Wait()
	camera.CameraType = Enum.CameraType.Custom
	ts:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Transparency = 1}):Play()
	print("yes")
	camShake:ShakeOnce(magnitude, roughness, fadeInTime, fadeOutTime, posInfluence, rotInfluence)
end)

It only printed the “did it work” part.

I don’t see the did it work print statement, though are there any errors in the console?

The two possibilities if the code is only partially running are that one part yields a long time (or forever) or that the code errors before finishing.

I would look for errors. If there are any, that’s the problem.

Otherwise, I would narrow down exactly which line it gets stuck on. That means that line is the problem.

The did it work print statement is actually called “Is this thing runnin”
Also there weren’t any errors.

I’m not sure what the problem is. You can use print statements to narrow down on which line it stops on.

The only line that seems like it might yield forever is

fade.Completed:Wait()

It shouldn’t yield forever though unless the tween finished before that’s called or the tween never started playing.

You could try replacing that with something like this

if fade.PlaybackState = Enum.PlaybackState.Playing then
    fade.Completed:Wait()
end

to prevent any possible problem with that line, though it might be from other lines. You can test which line is causing the problem with print statements as described in my last response.

I think I know what the problem is. The cutscene script is in startercharacterscripts (local script) So once the player gets respawned/revived, the script disappears and the script doesn’t run anymore. I added a task.wait(0.1) in the server script and it worked fine. But I’m not gonna do that since it pauses the server aka game.

was typing this when roblox was down

1 Like

the problem is that the client has to be fully loaded character use

    coroutine.wrap(function()
    task.wait(0.2) 
    player:LoadCharacter()
    player:SetAttribute("Dead", nil)
    end)()

using coroutine.wrap would make no issue

If this is the problem perhaps wrap the whole thing inside task.spawn(function() [your event handler code] end)?

I’m not sure about all the specifics of how Roblox stops code when the script it’s running from is deleted. I believe after the script is destroyed it does end the code once it reaches a yield (like task.wait), so it might be possible this is the problem.