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.
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
What is the issue?
Clicking the button a second time does not reset the tween…
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)
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:
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)