I’m trying to make it so if you touch a part a UI tweens in and out of the screen. It works the first time, but if I try and do it again it doesn’t work. Could someone please point out the issue?
local Part1 = workspace.Stage1Door.touchPart
local Part2 = workspace.Stage2Door.touchPart
local Part3 = workspace.Stage3Door.touchPart
local Part4 = workspace.Stage4Door.touchPart
local Sound = game.SoundService.Success
local SoundError = game.SoundService.Error
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local DB = false
local player = game.Players.LocalPlayer
local mainValue = game.ReplicatedStorage.StageValuesFolder.Stage1
local mainValue2 = game.ReplicatedStorage.StageValuesFolder.Stage2
local mainValue3 = game.ReplicatedStorage.StageValuesFolder.Stage3
local mainValue4 = game.ReplicatedStorage.StageValuesFolder.Stage4
local mainStats = require(game.ReplicatedStorage.stageValues)
Part1.Touched:Connect(function(Hit)
if not DB and Character == Hit.Parent and player.leaderstats.Cash.Value >= mainStats.StageCosts.Stage1.Cost and player.leaderstats.Level.Value >= mainStats.StageCosts.Stage1.Level and mainValue.Value == false then
DB = true
Sound:Play()
player.PlayerGui.Alert.AlertText.Text = "Stage 1 Unlocked!"
player.PlayerGui.Alert.AlertText.TextColor3 = Color3.fromRGB(34, 255, 0)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,0, 0),"In","Sine",0.75)
Sound.Ended:Wait()
wait(1)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,-1, 1),"Out","Sine",0.75)
DB = false
elseif player.leaderstats.Cash.Value < mainStats.StageCosts.Stage1.Cost or player.leaderstats.Level.Value < mainStats.StageCosts.Stage1.Level then
if not DB and Character == Hit.Parent and SoundError.IsPlaying == false then
DB = true
SoundError:Play()
player.PlayerGui.Alert.AlertText.Text = "Not enough!"
player.PlayerGui.Alert.AlertText.TextColor3 = Color3.fromRGB(255, 0, 0)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,0, 0),"In","Sine",0.75)
wait(3)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,-1, 1),"Out","Sine",0.75)
DB = false
end
end
end)
Part2.Touched:Connect(function(Hit)
if not DB and Character == Hit.Parent and player.leaderstats.Cash.Value >= mainStats.StageCosts.Stage2.Cost and player.leaderstats.Level.Value >= mainStats.StageCosts.Stage2.Level and mainValue2.Value == false then
DB = true
Sound:Play()
player.PlayerGui.Alert.AlertText.Text = "Stage 2 Unlocked!"
player.PlayerGui.Alert.AlertText.TextColor3 = Color3.fromRGB(34, 255, 0)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,0, 0),"In","Sine",0.75)
wait(1)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,-1, 1),"Out","Sine",0.75)
DB = false
elseif player.leaderstats.Cash.Value < mainStats.StageCosts.Stage2.Cost or player.leaderstats.Level.Value < mainStats.StageCosts.Stage2.Level then
if not DB and Character == Hit.Parent and SoundError.IsPlaying == false then
DB = true
SoundError:Play()
player.PlayerGui.Alert.AlertText.Text = "Not enough!"
player.PlayerGui.Alert.AlertText.TextColor3 = Color3.fromRGB(255, 0, 0)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,0, 0),"In","Sine",0.75)
wait(3)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,-1, 1),"Out","Sine",0.75)
DB = false
end
end
end)
Part3.Touched:Connect(function(Hit)
if not DB and Character == Hit.Parent and player.leaderstats.Cash.Value >= mainStats.StageCosts.Stage3.Cost and player.leaderstats.Level.Value >= mainStats.StageCosts.Stage3.Level and mainValue3.Value == false then
DB = true
Sound:Play()
player.PlayerGui.Alert.AlertText.Text = "Stage 3 Unlocked!"
player.PlayerGui.Alert.AlertText.TextColor3 = Color3.fromRGB(34, 255, 0)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,0, 0),"In","Sine",0.75)
wait(1)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,-1, 1),"Out","Sine",0.75)
DB = false
elseif player.leaderstats.Cash.Value < mainStats.StageCosts.Stage3.Cost or player.leaderstats.Level.Value < mainStats.StageCosts.Stage3.Level then
if not DB and Character == Hit.Parent and SoundError.IsPlaying == false then
DB = true
SoundError:Play()
player.PlayerGui.Alert.AlertText.Text = "Not enough!"
player.PlayerGui.Alert.AlertText.TextColor3 = Color3.fromRGB(255, 0, 0)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,0, 0),"In","Sine",0.75)
wait(3)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,-1, 1),"Out","Sine",0.75)
DB = false
end
end
end)
Part4.Touched:Connect(function(Hit)
if not DB and Character == Hit.Parent and player.leaderstats.Cash.Value >= mainStats.StageCosts.Stage4.Cost and player.leaderstats.Level.Value >= mainStats.StageCosts.Stage4.Level and mainValue4.Value == false then
DB = true
Sound:Play()
player.PlayerGui.Alert.AlertText.Text = "Stage 4 Unlocked!"
player.PlayerGui.Alert.AlertText.TextColor3 = Color3.fromRGB(34, 255, 0)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,0, 0),"In","Sine",0.75)
wait(1)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,-1, 1),"Out","Sine",0.75)
DB = false
elseif player.leaderstats.Cash.Value < mainStats.StageCosts.Stage4.Cost or player.leaderstats.Level.Value < mainStats.StageCosts.Stage4.Level then
if not DB and Character == Hit.Parent and SoundError.IsPlaying == false then
DB = true
SoundError:Play()
player.PlayerGui.Alert.AlertText.Text = "Not enough!"
player.PlayerGui.Alert.AlertText.TextColor3 = Color3.fromRGB(255, 0, 0)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,0, 0),"In","Sine",0.75)
wait(3)
player.PlayerGui.Alert.AlertText:TweenPosition(UDim2.new(0.438, 0,-1, 1),"Out","Sine",0.75)
DB = false
end
end
end)```