Model does not exist, even though it is

Hi, I have a problem.

SITUATION: I have streaming enabled this I require the use of :FindFirstChild, to check if the model is in workspace exist before proceeding with anything else.

PROBLEM: My :FindFirstChild says that the model does not exist, even though it is clearly loaded in the client (It is right infront of my. I am clearly seeing it.)

Here is the script, it is a local script.

	if workspace:FindFirstChild("Train") == true then
		TrainFloor = game.Workspace:WaitForChild("Train", 30):WaitForChild(TRAIN_BASE_NAME)
		table.insert(Include, TrainFloor)
	else
		print("e")
	end

It keeps on printing ā€œEā€, indicating the model is not in the client workspace even though it clearly is.

Not sure if this matters, but heres the whole script:

local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')

local LastTrainCFrame

local Function
local Function2

local TRAIN_BASE_NAME = "TrainFloor"

local DoOnce = false
local LastHit = nil


local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Include

local RootPart = player.Character:WaitForChild("Right Leg")
local Include = { }

local TrainFloor = nil

Function = RunService.Heartbeat:Connect(function()
	
	TrainFloor = nil

	table.clear(Include)
	
	if workspace:FindFirstChild("Train") == true then
		TrainFloor = game.Workspace:WaitForChild("Train", 30):WaitForChild(TRAIN_BASE_NAME)
		table.insert(Include, TrainFloor)
	else
		print("e")
	end
	
	
	
	TrainFloor = nil

	raycastParams.FilterDescendantsInstances = Include

	local result = workspace:Raycast(RootPart.CFrame.p, Vector3.new(0, -500, 0), raycastParams)
	if not result then
		return --nothing below the character
	end

	local Hit, Position, Normal, Material = result.Instance, result.Position, result.Normal, result.Material
	
	--------------------------------
	--print(Hit.Name)
	
	if DoOnce == false then
		DoOnce = true
		LastHit = Hit
	end
	
	if LastHit == Hit then
		--Do Nothing
	elseif LastHit ~= Hit then
		LastHit = Hit
		LastTrainCFrame = nil
	end
	

	local Train = nil
	local TrainCF = nil
	local Rel = nil
	
	
	if Hit and player.Character.Humanoid.Sit == false then
		--print("slay")
		-- MOVE PLAYER TO NEW POSITON FROM OLD POSITION:
		Train = Hit
		if LastTrainCFrame == nil then -- If no LastTrainCFrame exists, make one!
			LastTrainCFrame = Train.CFrame -- This is updated later.
		end

		TrainCF = Train.CFrame 
		Rel = TrainCF * LastTrainCFrame:inverse()
		LastTrainCFrame = Train.CFrame -- Updated here.
		RootPart.CFrame = Rel * RootPart.CFrame -- Set the player's CFrame
	else
		LastTrainCFrame = nil
		Train = nil
		TrainCF = nil
		Rel = nil
	end

end)




All help is appreciated :slight_smile:

1 Like

This will always equate to false due to variable types and the equality operator, the find first child function returns an instance and not true so instance does not equal true.

Try removing the == true bit.

2 Likes

I encountered the same problem before, i fixed it by disabling StreamingEnabled.
and also , remove the == true after the :FindFirstChild , like the other person said

1 Like

Did you forgot Train.Value?

1 Like

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