Localscript Struggles

Hi everyone, been scratching my head at this issue I’m having with a localscripts doortween. Sometimes I load into studio to test and it’s fine, door works as intended. But sometimes, I’ll load in and HotelDoorDetect is nil, and never gets found.

I’ve tried defining HotelDoorDetect using Waitforchild before the loop, alongside multiple waitforchilds for the Building, and Scriptables parts, neither solve this issue.

StreamingEnabled is false, the HotelDoorDetect part is Anchored, and exists in the client view explorer when in game.

I’ve done a lot of printing debugging, in the events that it can’t find HotelDoorDetect it’'s when the localscript recognises that “Scriptables” has 0 children.

In all the information I can find on the matter, they’ve said that you can use waitforchild on its parents as well, does not work.

local Replicated = game:GetService("ReplicatedStorage")
local OthFunctions = require(Replicated.ModuleScripts.LocalMovements)
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Runservice = game:GetService("RunService")



Runservice.Heartbeat:Connect(function()
	local Char = LocalPlayer.Character
	local HotelDoorDetect = game.Workspace["Building"].Scriptables:FindFirstChild("FrontDoorDetect")
	if HotelDoorDetect and Char and Char:FindFirstChild("HumanoidRootPart") then
		if (HotelDoorDetect.Position - Char.HumanoidRootPart.Position).Magnitude <= 10 and HotelDoorDetect.LocalOpenDoorVal.Value == false then
			OthFunctions.opendoor("Front", true)
		elseif (HotelDoorDetect.Position - Char.HumanoidRootPart.Position).Magnitude >= 10 and HotelDoorDetect.LocalOpenDoorVal.Value == true then
			OthFunctions.opendoor("Front", false)
		end
	end
end)

Thank you!

1 Like

Dont index stuff during runtime.
Grab it as a variable first so it gets cached.
Door could not be loaded to a player yet (mostly becouse of script being loaded prior to the object in workspace or due to content streaming) that why you should use WaitForChild.
Also doing game.Workspace is absolutelly not needed;
Script already has a global variable “workspace”.

Thank you for the reply, I tried using it as a variable before the runtime. I still ran into the same issue even using waitforchild, the script would never reach the heartbeat function because it would constantly be waiting for it to be defined.

Just realised I had 2 folders titled scriptables, just spent like 8 hours wondering why this wasn’t working :cry:

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