Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Value shows up as nul when used in a script?

Asked by 4 years ago

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.

0
Is doorName a reference to a model, or a model's name? xXprohax0r1337Xx 74 — 4y
0
doorName is a referance to the model of a door codee21 4 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

0
I have doorName set to a model of a door, not a player's character. The Humanoid is used to animate the door. codee21 4 — 4y
0
Oh ok Block_manvn 395 — 4y
Ad
Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
4 years ago
Edited 4 years ago

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
0
Yeah, I have a humanoid in the door so i can run an animation for the door to open. codee21 4 — 4y

Answer this question