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

Value shows up as nul when used in a script?

I am trying to make a script that when a character opens a door, it opens for the entire server. So i made it go through a server event, with the doorName value as the name of the door. but whenever I run this script:

local function openDoor(player, doorName)
	doorName.Humanoid:Destroy()
end

the output says that "Humanoid" is a nul value, when there definitely a humanoid in the model.

doorName is set to the value of a string value with the location of the door model, I don't know if that has anything to do with it or not.

2 comments

0

Is doorName a reference to a model, or a model's name?

0

doorName is a referance to the model of a door

2 answers

Why you do doorName.Humanoid instend of player.Character.Humanoid, the player is contain the character which is a model that contain humanoid.

2 comments

0

I have doorName set to a model of a door, not a player's character. The Humanoid is used to animate the door.

0

Oh ok

Simple the players Character did not load all the way when it ran so it returned nil. Here's a fix! as well I do not know why you had doorName for the humanoid. You can use player as for getting this. Just wanted to say as well, DO NOT USE HUMANOIDS FOR DOORS AS THEY ARE VERY EXPLOITABLE EVEN THOUGH FILTERING ENABLED IS ON

local function openDoor(player, doorName)
    local char = player.Character or player.CharacterAdded:Wait()
    char:WaitForChild("Humanoid"):Destroy()
end

if you want it that way for using a humanoid in the door here I guess... Also change the doorname to the models parent like "game.Workspace.door"

local function openDoor(player, doorName)
    local humanoid = doorName.Humanoid or doorName:WaitForChild("Humanoid")
    humanoid:Destroy()
end

1 comment

0

Yeah, I have a humanoid in the door so i can run an animation for the door to open.

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