Scripting Error

  1. What do you want to achieve?
    I want to make the Entity, “The part”, to go to the recent door thats opened by the player.
  2. What is the issue?
    The function works, but the problem is when the entity spawns and if the player continues to open new doors, the entity doesn’t go that far because it thinks that the door it went was the “recent door.”
  3. What solutions have you tried so far?
    I used task.wait, which did nothing.
local Part = script.Parent

local TweenService = game:GetService("TweenService")
local ServerScript = game:GetService("ServerScriptService")
local NumberVal = ServerScript.DoorNum:WaitForChild("NumberVal")




local tweenInfo = TweenInfo.new(
	5, 
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out, 
	0,
	false, 
	0 
)

local tween = TweenService:Create(Part, tweenInfo, { Position = game.Workspace.Doors:FindFirstChild("Door"..tostring(NumberVal.Value)).PrimaryPart.Position + Vector3.new(0,2.5,0) })

if Part.Parent == workspace then
	tween:Play()
	script.Parent.PlaySound:Play()
	script.Parent.Footsteps:Play()
	wait(5)
	script.Parent.PlaySound:Stop()
	script.Parent.Footsteps:Stop()
	Part:Destroy()
end
1 Like

There’s not much code to go through, not even the navigation code for the entity. Would you be fine sending us the code of the entity’s navigation?

I would also recommend rewording your post’s title to match your issue, instead of a generic “Scripting Error”.

From what you sent, it looks like your code is only being executed once because it’s not wrapped in an Event. Which is why the entity only goes to one door.

You need to create an event that fires once every time a door is opened. Either a BindableEvent or a RemoteEvent depending on your use case. Then wrap your code in that event so that it executes every time that event is fired.