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

Help with simple script?

I am making a hockey game what I want in this script is when the hockey ball touched a part named "RedGoal" then the hockey ball gets removed.

RG = game.Workspace.RedGoal
BG = game.Workspace.BlueGoal

RS = game.Workspace.RedScore
BS = game.Workspace.BlueScore

script.Parent.Touched:connect(function(part)
	if part:ClassName("RedGoal") then
		script.Parent:remove()
	end
end)

1 answer

ClassName is not a method. It looks like you're just trying to check the Name.

Change

if part:ClassName("RedGoal") then

to

if part.Name == "RedGoal" then

I also recommend not using remove and instead setting the Parent to nil or using Destroy.

4 comments

0

The remove function already sets the object's Parent to nil. Just doing so will alter nothing.

0

The remove function is deprecated.

0

^ Yeah, @Goul essentially what :remove() does is it doesn't actually delete the instance from the server's memory. When :Destroy() is used, it detaches itself and its children from their respective parents, and effectively deletes it from server memory, freeing up processing capacity.

0

remove sets the parent to nil, destroy locks it.

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