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

Wanting to make a character nil on touch?

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)

1 comment

2

use a code block please

2 answers

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)

2 comments

0

He wanted the humanoid to be nil, not its parent.

0

But you're just nilling the variable, it doesn't have any effect in workspace

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)

4 comments

0

He wants to parent the humanoid to nil, not to erase the reference to it

0

Also, your script has a syntax error at line 8

0

"I was wanting to find the characters humanoid and make it nil." - that's what the code does.

0

Please don't downvote my correct answer, and then re-upload it with an incorrect change.

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