Why this script runs only once

  1. What do you want to achieve? Keep it simple and clear!
    Hello fellow developers of roblox, so for some reason script being called once and only once, by using prints for debounce i figured out what scripts thinks player is not inside of a region.
  2. What is the issue? Include screenshots / videos if possible!
    Described in 1st.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? As i already stated, i used prints for debounce.

Code:

local Prompt = script.Parent
local Region = script.Parent.Parent.Parent.Parent.Region
local CloseThing = script.Parent.Parent.Parent.Parent.CloseThing
local TweenService = game:GetService("TweenService")
local Time = 5

CloseThing.Transparency = 1
CloseThing.CanCollide = false

function isInsideBrick(position, brick)
	local v3 = brick.CFrame:PointToObjectSpace(position)
	return (math.abs(v3.X) <= brick.Size.X / 2)
		and (math.abs(v3.Y) <= brick.Size.Y / 2)
		and (math.abs(v3.Z) <= brick.Size.Z / 2)
end

Prompt.Triggered:Connect(function(Plr)
	local Torso = Plr.Character.PrimaryPart
	print("Found Torso")
	if (Torso and isInsideBrick(Torso.Position, Region)) then
		print("Torso is inside brick")
	Torso.Anchored = true
	local MoveUp = TweenService:Create(Torso, TweenInfo.new(Time, Enum.EasingStyle.Quad), {Position =  CloseThing.Position + Vector3.new(0,6,0)})
	MoveUp:Play()
	Torso.Anchored = false
	CloseThing.Transparency = 0
	CloseThing.CanCollide = true
	task.wait(Time)
	CloseThing.Transparency = 1
	CloseThing.CanCollide = false
		end
end)
1 Like

Some additional info:
REGION Is Anchored, and this is not a problem.
REGION position is always same it’s do not change by script or somehow other.
REGION Is right size and fully fits exact place where i use it.

Because isInsideBrick doesn’t return true

Don’t really understand then how it being runned once :confused:

So it works, but only runs once?

Yeah, i already stated that in title

Are you sure it doesn’t get stuck during/after the tween? You should make more checks to test that.

When you said it ran once do you mean when you trigger the prompt it run once or whenever you trigger the prompt it only run one time and not the other time you trigger the prompt again?

second. It just do nothing on second trigger

k, let me test. (30 letterssss)

Alright bumping this topic, I added tons prints as @enpiesie said and this didn’t give any result, all prints run only once. Code

local Prompt = script.Parent
local Region = script.Parent.Parent.Parent.Parent.Region
local CloseThing = script.Parent.Parent.Parent.Parent.CloseThing
local TweenService = game:GetService("TweenService")
local Time = 5
local Deb = false

CloseThing.Transparency = 1
CloseThing.CanCollide = false

function isInsideBrick(position, brick)
	local v3 = brick.CFrame:PointToObjectSpace(position)
	return (math.abs(v3.X) <= brick.Size.X / 2)
		and (math.abs(v3.Y) <= brick.Size.Y / 2)
		and (math.abs(v3.Z) <= brick.Size.Z / 2)
end

Prompt.Triggered:Connect(function(Plr)
	if Deb then return end
	Deb = true
	local Torso = Plr.Character.PrimaryPart
	print("Found torso, deb is true, torso inside brick")
	if Torso and isInsideBrick(Torso.Position, Region) then
	Torso.Anchored = true
	local MoveUp = TweenService:Create(Torso, TweenInfo.new(Time, Enum.EasingStyle.Quad), {Position =  CloseThing.Position + Vector3.new(0,7,0)})
	print("Tween Created")
	MoveUp:Play(); MoveUp.Completed:Wait()
	print("Tween finished playing")
	Torso.Anchored = false
	CloseThing.Transparency = 0
	CloseThing.CanCollide = true
	task.wait(Time)
	print("Task has been successfully executed.")
	CloseThing.Transparency = 1
	CloseThing.CanCollide = false
	Deb = false
	end
end)


First run

bumping dead topic (30 letterssssss)

Bruh proximity prompt don’t even get triggered on second trigger

Could you add a print before “Deb = false”?

I have changed code a bit

 local Prompt = script.Parent
local Region = script.Parent.Parent.Parent.Parent.Region
local CloseThing = script.Parent.Parent.Parent.Parent.CloseThing
local TweenService = game:GetService("TweenService")
local Time = 5
local Deb = false

Prompt.Triggered:Connect(function(Plr)
	print("Prompt triggered and Deb = "..Deb)
	if Deb then return end
	Deb = true
	local Torso = Plr.Character.PrimaryPart
	print("Found torso, deb is true, torso inside brick")
	if Torso and isInsideBrick(Torso.Position, Region) then
		Torso.Anchored = true
		local MoveUp = TweenService:Create(Torso, TweenInfo.new(Time, Enum.EasingStyle.Quad), {Position =  CloseThing.Position + Vector3.new(0,7,0)})
		print("Tween Created")
		MoveUp:Play(); MoveUp.Completed:Wait()
		print("Tween finished playing")
		Torso.Anchored = false
		CloseThing.Transparency = 0
		CloseThing.CanCollide = true
		task.wait(Time)
		print("Task has been successfully executed.")
		CloseThing.Transparency = 1
		CloseThing.CanCollide = false
	end
	Deb = false
end)

function isInsideBrick(position, brick)
	local v3 = brick.CFrame:PointToObjectSpace(position)
	return (math.abs(v3.X) <= brick.Size.X / 2)
		and (math.abs(v3.Y) <= brick.Size.Y / 2)
		and (math.abs(v3.Z) <= brick.Size.Z / 2)
end

I think it got stuck because the “Deb = false” was inside an if statement.

Could you tell us what the output is after you trigger it the second time? (wait for 10 seconds before triggering)

Literally this didn’t even got an result when i put deb outside if and proximity prompt even not get triggered on second run

But the if statement ran, so that couldn’t be the issue

What does it print after the second time?