Item is not part of model "Workspace.Player" even though it is

I have this script that adds the boolean value “onRed” to the player, however, when another script tries to access it, it just says "onRed is not part of model “Workspace.PANDASonNOOB”, however, it is very clear that onRed is parented to the player. What is the problem here?

btw i am accessing onRed a while after spawning, so it couldn’t be that onRed hasn’t been set yet

Sometimes this happens when the player hasn’t fully loaded in yet. You might need to add a wait() to the script.

I know, but the player and the onRed has already been loaded a long time before the error occurs

Can’t tell from your Explorer window picture but are you sure you have Workspace.PANDASonNOOB selected, or are you looking in Players.PANDASonNOOB?

that is in the workspace, should I instead try to put it in players?

In my opinion, yes, you do have to put it in Players.Player. This might be happening because you created that value using a local script and you are trying to access the value from a server script.

Your script is looking in Workspace.PANDASonNOOB.
You also cut off the first letter in your screenshot, I can only see “nRed” in the image. Did you misspell onRed in the script?

1 Like

No (the cut off letter was a mistkae), it does say onRed

I think it’s better if you give us a look of your script. It’s easier to debug that way.

Screen Shot 2022-07-28 at 12.40.35 PM
local script inside the player:

local plr = script.Parent
local t = plr:WaitForChild("LowerTorso")
local player = game.Players:GetPlayerFromCharacter(plr)
local onRed = Instance.new("BoolValue", player)
onRed.Name = "onRed"
onRed.Value = false

script inside of part:

part = script.Parent

part.Touched:Connect(function(hit)
	if not hit.Parent:FindFirstChildWhichIsA("Humanoid") == nil then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		player.onRed.Value = false
		print(hit.Parent)
		print(player.onRed.Value)
		wait(0.1)
	end
end)

part.TouchEnded:Connect(function(part)
	if part.Parent:FindFirstChildWhichIsA("Humanoid") == nil then return end
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
	player.onRed.Value = false
	print(part.Parent)
	print(player.onRed.Value)
end)

Exactly what I was expecting.
Remove the local script inside the player and add a server script in server script service and add the following in it:

game.Players.PlayerAdded:Connect(function(player)
	local onRed = Instance.new("BoolValue", player)
	onRed.Name = "onRed"
	onRed.Value = false
end)

Everything should work just fine after you make the changes.

1 Like