Problem with cancelling a tween

  1. What do you want to achieve? Keep it simple and clear!

I want that when the player dies the freeze tween stops

  1. What is the issue? Include screenshots / videos if possible!

The problem is that it works but only once, that means that if i die once it works but if i die again it doesnt work

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried using a while wait() do loop but it didnt work

Heres the code, its a local script located inside a gui

-- 
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local gui = script.Parent
local image = gui.ImageLabel
local sound = gui.Freeze_s
local char = plr.Character
local hum = char.Humanoid
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(
	0.5,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local canceltween = ts:Create(image,ti,{ImageTransparency = 1})
local cancelsound = ts:Create(sound,ti,{Volume = 0, Playing = false})

hum.Died:Connect(function()
	canceltween:Play()
	cancelsound:Play()
end)
5 Likes

Check if the tween stays the same after the first death. If it is, then you need to somewhat reset the tween

3 Likes

could be something to do with resetonspawn, try check if thats on?

2 Likes

I think the issue is that after you die, you get a new humanoid, meaning you have to change the humanoid variable to the new humanoid. Try getting the humanoid after the player’s character respawns like this:

plr.CharacterAdded:Connect(function(char)
	local hum = char:WaitForChild("Humanoid")
	
	hum.Died:Connect(function()
		canceltween:Play()
		cancelsound:Play()
	end)
end)
3 Likes
local function onCharAdded(char)
  char:WaitForChild("Humanoid").Died:Connect(function()
    -- play tweens
  end)
end

plr.CharacterAdded:Connect(onCharAdded)
if plr.Character then
  onCharAdded(plr.Character)
end
2 Likes

Thank you. it worked perfectly

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