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

Removing part on touch?

This gives me 1 point when it is touched. When it is touched, how would I make it removed?

amnt = 1
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local score = stats:findFirstChild("Points")
				if (score~=nil) then
					score.Value = score.Value + amnt
					
				end
			end
		end
		
	end
end

script.Parent.Touched:connect(onTouched)
script.Parent.Touched:Remove()

1 answer

✓ Accepted answer

You simply need to use the :Destroy() method. It removes the part exactly how you want.

We'll use it like this:

game.Workspace.Part:Destroy() --Destroys the part

Now let's apply it to your script:

amnt = 1
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local score = stats:findFirstChild("Points")
				if (score~=nil) then
					score.Value = score.Value + amnt
					script.Parent:Destroy() --Added it in right here to destroy part
				end
			end
		end
	end
end

script.Parent.Touched:connect(onTouched)

It should work now.


Anyways, hope this helped. If you have any further problems/questions, please leave a comment below :P

####-Dyler3

2 comments

1

Thanks!

0

No prob, glad I could help :p

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