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

Help with simple script?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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.

0
The remove function already sets the object's Parent to nil. Just doing so will alter nothing. Goulstem 8144 — 8y
0
The remove function is deprecated. 1waffle1 2908 — 8y
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. Legojoker 345 — 8y
0
remove sets the parent to nil, destroy locks it. 1waffle1 2908 — 8y
Ad

Answer this question