Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to find any part given a certain name in WorkSpace with a LocalScript?

So here's my problem and I'll be quick , this LocalScript only updates every time the player dies. And I'll give you an clear example,

In workspace the LocalScript detects where the position of a part named "Lock On!" is.

But If I change the current name of the part to something like "Eric" for example and then name another part "Lock On!", the script for some reason doesn't detect the other part given that same name until after the player dies.

Another Example if I delete the a part named "Lock On" and spawn another part named "Lock On"

How can I change it so it updates constantly? like every second, every minute, all of the time.

--The Parent of this script is a Vector3Value
local LockOn = game.Workspace:FindFirstChild("Lock On!")

game:GetService("RunService").RenderStepped:Connect(function()
script.Parent.Value = LockOn.Position
end)

1 answer

✓ Accepted answer

You could define the LockOn variable inside of your event. This way, it will update everytime the event fires.

game:GetService("RunService").RenderStepped:Connect(function()
	local LockOn = workspace:FindFirstChild("Lock On!")
	--In case LockOn is nil use an `or` statement
	script.Parent.Value = LockOn.Position or script.Parent.Value
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.