So basically im working on a teamwork obby game, and im trying to make a button to make a path appear and disappear. But for some reason it doesnt work?
I don’t know how to fix it or what to do, heres the code:
local part = script.Parent
local touching = script.Parent.Parent.Touching
local Path = workspace.TestPath
local button = script.Parent.Parent.Button_top
local tweenserivce = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(.3, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)
local ismoving = false
local initialSize = button.Size
local initialPosition = button.Position
local targetHeight = initialSize.Y * 0.25
local function onAnimationComplete()
ismoving = false
end
part.Touched:Connect(function(hit)
local character= nil
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local character = humanoid.Parent
end
if ismoving then print("moving, skipping...") return end
ismoving = true
print("Touched event triggered")
local targetPosition = initialPosition - Vector3.new(0, initialSize.Y / 2, 0)
local targetSize = Vector3.new(initialSize.X, targetHeight, initialSize.Z)
local InPosition = tweenserivce:Create(button, tweeninfo, {Position = targetPosition})
local InSize = tweenserivce:Create(button, tweeninfo, {Size = targetSize})
local path = tweenserivce:Create(Path, tweeninfo, {Transparency = 0})
path.Completed:Connect(onAnimationComplete)
InPosition.Completed:Connect(onAnimationComplete)
InSize.Completed:Connect(onAnimationComplete)
path:Play()
InPosition:Play()
InSize:Play()
Path.CanCollide = true
wait(.3)
if character then
print("Still touching")
elseif character == nil then
ismoving = true
print("TouchEnded event triggered")
local outPosition = tweenserivce:Create(button, tweeninfo, {Position = initialPosition})
local outSize = tweenserivce:Create(button, tweeninfo, {Size = initialSize})
local path2 = tweenserivce:Create(Path, tweeninfo, {Transparency = 1})
outPosition.Completed:Connect(onAnimationComplete)
outSize.Completed:Connect(onAnimationComplete)
outPosition:Play()
outSize:Play()
path2:Play()
Path.CanCollide = false
end
end)
part.TouchEnded:Connect(function()
if ismoving then print("moving, skipping...") return end
ismoving = true
print("TouchEnded event triggered")
local outPosition = tweenserivce:Create(button, tweeninfo, {Position = initialPosition})
local outSize = tweenserivce:Create(button, tweeninfo, {Size = initialSize})
local path2 = tweenserivce:Create(Path, tweeninfo, {Transparency = 1})
outPosition.Completed:Connect(onAnimationComplete)
outSize.Completed:Connect(onAnimationComplete)
outPosition:Play()
outSize:Play()
path2:Play()
Path.CanCollide = false
end)