Problem with tweening for my obby

So I am trying to make client-sided flooding via button for my obby. When you click a button, it starts a client-sided flood which is required to beat the stage.

  1. What do you want to achieve?

When the player dies from the flood, I want the flood to reset to its original position, and to cancel the tween. I was able to make it work, but it only works one time. Clicking the button a second time does not cancel the tween

  1. What is the issue?

Clicking the button a second time does not reset the tween…

Video of the problem (roblox doesn’t let me upload)

  1. **What solutions have you tried so far?

I have tried using while loops to constantly check if the player has died but nothing has worked. I don’t really know what else I should do.

Below is the mainscript:

StarterPlayer → StaterPlayerScripts → Modulescript → Folder (called floods) → LocalScript

local TweenService = game:GetService("TweenService")
local parts = game.Workspace.FloodEscapeParts
local lava = parts.Lava:FindFirstChild("Lava1") -- change if duplicated lava
local button = parts.ButtonParts.Button1.ClickDetector
local touched = lava.Touched
local variables = require(script.Parent.Parent)

local increment = 57 -- Height to raise the lava (xyz)
local duration = 9 -- Duration in seconds

local goal = {}
goal.Position = lava.Position + Vector3.new(0, increment, 0)

local tweenInfo = TweenInfo.new(
	duration, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.In, -- EasingDirection
	0, -- RepeatCount (0 = do not repeat)
	false, -- Reverses (tween not reversed)
	0.5 -- DelayTime
)

local tween = TweenService:Create(lava, tweenInfo, goal)

local startpos = Vector3.new(-66, 28, -161.5)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local died = true

touched:Connect(variables.onLavaTouched)
--where the problem is I think
button.MouseClick:Connect(function()
	lava.Position = startpos
	tween:Play()
end)

humanoid.Died:Connect(function()
	lava.Position = startpos
	tween:Cancel()
end)

Please and thank you!

2 Likes

cancel the tween before moving the kill part to the start pos

humanoid.Died:Connect(function()
	tween:Cancel()
    lava.Position = startpos
end)
2 Likes

You could try making a new tween for every button click, as well as making sure to destroy the old one.

1 Like

did what you said, but the problem still persists…

when the character loads again you need to rereference the character and humanoid, and setup the humanoid died event again, since this is in starterplayerscripts
try replacing the humanoid died function with this:

player.CharacterAdded:Connect(function(char)
    character = char
    character:WaitForChild("Humanoid").Died:Connect(function()
	    lava.Position = startpos
	    tween:Cancel()
    end)
end)

also remove the previous character/humanoid assignment since the waitforchild will prevent the character first load from being detected

1 Like

rewritten script:

local TweenService = game:GetService("TweenService")
local parts = game.Workspace.FloodEscapeParts
local lava = parts.Lava:FindFirstChild("Lava1") -- change if duplicated lava
local button = parts.ButtonParts.Button1.ClickDetector
local touched = lava.Touched
local variables = require(script.Parent.Parent)

local increment = 57 -- Height to raise the lava (xyz)
local duration = 9 -- Duration in seconds

local goal = {}
goal.Position = lava.Position + Vector3.new(0, increment, 0)

local tweenInfo = TweenInfo.new(
	duration, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.In, -- EasingDirection
	0, -- RepeatCount (0 = do not repeat)
	false, -- Reverses (tween not reversed)
	0.5 -- DelayTime
)

local tween = TweenService:Create(lava, tweenInfo, goal)

local startpos = Vector3.new(-66, 28, -161.5)
local player = game.Players.LocalPlayer
local died = true

player.CharacterAdded:Connect(function(char)
    char:WaitForChild("Humanoid").Died:Connect(function()
	    lava.Position = startpos
	    tween:Cancel()
    end)
end)

touched:Connect(variables.onLavaTouched)
--where the problem is I think
button.MouseClick:Connect(function()
	lava.Position = startpos
	tween:Play()
end)
1 Like

This works! thanks for helping me out!

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