:FindFirstChild() acting funny

I’m trying to create a very simple script that inserts a LocalScript into the player’s character. For some other miscellaneous reasons, it can’t be put straight into StarterCharacterScripts.

local part = script.Parent
local localScript = part.ForceFirstPerson

	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		if player:FindFirstChild("ForceFirstPerson") ~= nil then return end
		local newLocalScript = localScript:Clone()
		newLocalScript.Parent = player.Character
		newLocalScript.Enabled = true

I’ve determined that the issue with this script would seem to be the :FindFirstChild() statement, unless I am mistaken. For context, this is in a regular script. When you touch the part, it skips over the :FindFirstChild() and duplicates a bajillion local scripts.

My main question is that can anybody help me get to the root of this problem, or find a workaround?

Have you tried :WaitForChild() to see if it yields?

(you can just do if player:FindFirstChild("ForceFirstPerson") then return end btw)

I’ve replaced the :FindFirstChild() with :WaitForChild(), and I’ve confirmed that it does indeed yield.

Does player.ForceFirstPerson load on client?

The script is located within a part, and the localscript is a descendant of said script.

sorry for late response time, i lost control of the day

newLocalScript.Parent = player.Character
Puts it in CHARACTER

Checks in the PLAYER


if player.Character:FindFirstChild("ForceFirstPerson") then return end

That makes a lot of sense… silly oversight by me. Going to mark this as the solution, thank you for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.