Code only works once

Ive been trying to make this little animation thing when you teleport here is my code:



script.Parent:WaitForChild("BlackoutEvent").OnClientEvent:Connect(function()

	print("blackout")
	if db == false then
		db = true
		script.Parent.Blackout.BackgroundTransparency = 0
		script.Parent.Blackout:TweenSize(UDim2.new(1, 0, 1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.25)
		wait(0.5)
		script.Parent["Baseball Bat Swing 6 (SFX)"]:Play()
		script.Parent.Blackout:TweenSizeAndPosition(UDim2.new(0,0,0,0),UDim2.new(0.5,0,0.5,0), 0.1)
		script.Parent.Blackout.Position = UDim2.new(0, 0, 0, 0)
		script.Parent.Blackout.Size = UDim2.new(0, 0, 0, 0)

		db = false
	end

end) 

For some reason it only works once then it starts tweening the corner. Anyone know why?

Show me both of the scripts and I might be able to help.

this is the only script that tweens.

I think they meant the script that fires the remoteEvent that you’ve provided.

2 Likes

Oh. Its when a player touches a door. The script fires its just that the tween glitches out. I think because of me doing something wrong. But basicly the thing worked once but not twice

Could you show the script? That would help them identify the problem. I cant cuz I got class.

Ok


local db = false

local parent = script.Parent
parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and parent.Parent.Owner.Value ~= "nil" and db == false and parent.Parent.Locked.Value == false then
		print(hit)
		db = true
		local properties1 = {
			CFrame = script.Parent.Parent.Door2.CFrame
		}
		local properties2 = {
			CFrame = script.Parent.Parent.Door1.CFrame
		}
		
		local tweenfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
		local tween = tweenservice:Create(script.Parent.Parent.Door1, tweenfo, properties1)
		tween:Play()
		script.Parent.door_open:Play()
		wait(0.2)
		
		wait(3)
		local tween2 = tweenservice:Create(script.Parent.Parent.Door1, tweenfo, properties2)
		tween2:Play()
		script.Parent["Door_Close01 (Source)"]:Play()
		wait(0.2)
		db = false
	elseif db == false and hit.Parent:FindFirstChild("Humanoid") and parent.Parent.Owner.Value == hit.Parent.Name then
		print(hit)
		db = true
		local properties1 = {
			CFrame = script.Parent.Parent.Door2.CFrame
		}
		local properties2 = {
			CFrame = script.Parent.Parent.Door1.CFrame
		}

		local tweenfo = TweenInfo.new(0.2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
		local tween = tweenservice:Create(script.Parent.Parent.Door1, tweenfo, properties1)
		tween:Play()
		script.Parent.door_open:Play()
		wait(0.2)

		wait(3)
		local tween2 = tweenservice:Create(script.Parent.Parent.Door1, tweenfo, properties2)
		tween2:Play()
		script.Parent["Door_Close01 (Source)"]:Play()
		wait(0.2)
		db = false
	end
end)```

oh wrong script sorry

   local db = false
   if hit.Parent:FindFirstChild("Humanoid") and db == false then
   	db = true
   	local name = hit.Parent.Name
   	if name == script.Parent.Parent.Owner.Value then
   		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
   		player.IsHome.Value = true
   		player.PlayerGui.DeleteGui.Enabled = true
   		local ui = player.PlayerGui:WaitForChild("TP_ui")
   		ui.BlackoutEvent:FireClient(player)
   		local plot = script.Parent.Parent
   		local plotnumber = plot.Plot.Value
   		wait(1)
   		for i, v in pairs(game.Workspace.Plots:GetChildren()) do
   			if v.PlotNumber.Value == plotnumber then
   				hit.Parent.HumanoidRootPart.CFrame = v.Base.CFrame+Vector3.new(0, 5, 0)
   			end
   		end
   	elseif script.Parent.Parent.Locked.Value == false and script.Parent.Parent.Owner.Value ~= "nil" then
   		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
   		local ui = player.PlayerGui:WaitForChild("TP_ui")
   		ui.BlackoutEvent:FireClient(player)
   		local plot = script.Parent.Parent
   		local plotnumber = plot.Plot.Value
   		wait(1)
   		for i, v in pairs(game.Workspace.Plots:GetChildren()) do
   			if v.PlotNumber.Value == plotnumber then
   				hit.Parent.HumanoidRootPart.CFrame = v.Base.CFrame+Vector3.new(0, 5, 0)
   			end
   		end
   	end 
   	db = false
   end
end)