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

Wanting to make a character nil on touch?

Asked by
X8311 0
6 years ago

I have this written, and instead of breaking the characters joints, I was wanting to find the characters humanoid and make it nil. Thanks!

local name = "X8311"

local id = 10073558

script.Parent.Touched:connect(function(hit) local h = hit.Parent:findFirstChild("Humanoid") if h then local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then if plr:IsBestFriendsWith(id) or plr.Name == name then script.Parent.Transparency = 1 script.Parent.CanCollide = true wait(.3) script.Parent.Transparency = 1 script.Parent.CanCollide = false else hit:BreakJoints() end end end end)

2
use a code block please awesomeipod 607 — 6y

2 answers

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Set the Parent of hit.Parent.Humanoid to nil

local name = "X8311"

local id = 10073558
script.Parent.Touched:connect(function(hit)
    local h = hit.Parent:findFirstChild("Humanoid")
    if h then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr then
            if plr:IsBestFriendsWith(id) or plr.Name == name then
                script.Parent.Transparency = 1
                script.Parent.CanCollide = true
                wait(.3)
                script.Parent.Transparency = 1
                script.Parent.CanCollide = false
            else
                hit.Parent.Humanoid.Parent = nil
            end
        end
    end
end)
0
He wanted the humanoid to be nil, not its parent. CherryLeaves 32 — 6y
0
But you're just nilling the variable, it doesn't have any effect in workspace Amiaa16 3227 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago
Edited 6 years ago

You can make it nil by h = nil.

local name = "X8311"
local id = 10073558

script.Parent.Touched:connect(function(hit)
    local h = hit.Parent:findFirstChild("Humanoid")
    if h then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr and plr:IsBestFriendsWith(id) or plr.Name == name then   
            script.Parent.Transparency = 1
            script.Parent.CanCollide = true
            wait(0.3)
            script.Parent.Transparency = 1 
            script.Parent.CanCollide = false
        else
            h = nil
        end
    end
 end)
0
He wants to parent the humanoid to nil, not to erase the reference to it Amiaa16 3227 — 6y
0
Also, your script has a syntax error at line 8 Amiaa16 3227 — 6y
0
"I was wanting to find the characters humanoid and make it nil." - that's what the code does. CherryLeaves 32 — 6y
0
Please don't downvote my correct answer, and then re-upload it with an incorrect change. CherryLeaves 32 — 6y

Answer this question