Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My script isn't getting the humanoidrootpart even though it's there?

This script gives the error: HumanoidRootPart is not a valid member of Model. When I print the 'char' it gives me my username (zomspi). This script runs when the character dies, when I die it runs that error.

wait(0.1)
local char = game.Workspace[script.Parent.Parent.Name]
local hrp = char.HumanoidRootPart

		while true do
			wait(1)
		if (script.Parent.Position - hrp.Position).magnitude < 30 then
			
			local nextlevel = math.random(1, #game.ServerStorage.Levels:GetChildren())
			local level = game.ServerStorage.Levels:FindFirstChild(nextlevel):Clone()
			level.Parent = script.Parent.Parent
			level:SetPrimaryPartCFrame(script.Parent.Parent.PrimaryPart.CFrame + Vector3.new(0,0,-53))
			wait(0.25)
		
			if script and script.Parent then
			script.Parent:Destroy()
			end
			break
			
			end
		end

Thanks!

EDIT: I figured out 'char' is equal to the name of my character, not my character, I still don't know how to fix it or why it's getting the name and not the character / model.

2 answers

I'm not sure exactly why this error occurs. However, I can think of one reason why this is not working.

You have another model in your workspace with the name zomspi that does not have a hrp. Instead of using local char = game.Workspace[script.Parent.Parent.Name], try using local char = script.Parent.Parent.Character. (I'm assuming that script.Parent.Parent is the player)

Your "char" variable is set as the name of your character, not the character itself. The script then tries to index (or search) the string "zomspi", which it obviously cannot do. Set your variable to what I have below.

local char = game.Workspace[script.Parent.Parent]
-- Or you can flat out have the script part.
local char = script.Parent.Parent

Furthermore, I'm not sure that the HumanoidRootPart stays upon death since everything is disconnected. Don't quote me, however.

This discussion is preserved as it was. New answers, comments, and votes are closed.