HumanoidRootPart is not a valid member of Model "Workspace.rolego222"

  1. What do you want to achieve?

I am making a tool that spawns a model on the player’s HumanoidRootPart when activated.

  1. What is the issue?

when i run this code:

local function onPlayerAdded()


local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local chair = game.ReplicatedStorage.epic_chair
local IsChairSpawned = false
local tool = script.Parent
print "yes"

local function spawnchair()
	
	local positionArray = {character.HumanoidRootPart.Position}
	local chairclone = chair:Clone()
	chairclone.Parent = game.Workspace
	chairclone.Position = positionArray[1]
	local IsChairSpawned = true

end

while(true)do
	if tool.Activated then
		if not IsChairSpawned then
			spawnchair()
		end
	end
end
end

game.Players.LocalPlayer.CharacterAdded:Connect(onPlayerAdded())

It gives me the error in the title.

  1. What solutions have you tried so far?

I’ve tried looking all over the DevForum for help but i could not find anything.

What am I doing wrong here?

Edit: the Error is on line 13

First thing first, why are you using an event inside a while loop?

you can just leave it as

tool.Activated:Connect(fuction()

sorry i’m very new to scripting

Also, how would I check the “if not IsChairSpawned” condition that way?

Did you mean

tool.Activated:Connect(function()

? I think you forgot an n in (function()

nevermind i got it, no need to continue this thread