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

Trying to make it so the Rose gets deleted?

Asked by
Ywis 5
9 years ago

Hello all, this is my very first question I've posted, Please keep in mind that I've just started scripting, playing around free models and such.

I've come upon an idea where people would 'backspace' their tool - which is a Rose then whenever some one touches it, it will be deleted.

This is the script I have currently,

function OnTouch()
    handle:Destroy()
    Part:Destroy()
end

handle = game.Workspace.Rose.Handle
Part = game.Workspace.Rose.Part

However whenever the Rose is 'backspaced', the tool goes from the StarterPackto Workspace, even if it's touched, it would go back to the players StarterPack, is there anyway that I could turn this Tool in to a Model if it's 'backspaced'?

Thank You

2 answers

Log in to vote
2
Answered by 9 years ago

I assume the script is a child of the Tool (the rose)? If so, you can navigate to it through the hierarchy, rather than defining it through workspace.

Imagine if you have two roses in Workspace. Both are named "Rose". Both scripts look for "game.Workspace.Rose". Both scripts will find the first rose, but neither will find the second. You understand that issue?

The solution to the issue is, as I said, to navigate through the hierarchy. The other issue with your script is that it has no connection-line, so the Touched-event isn't actually ever fired.

handle = script.Parent.Handle -- script.Parent is the tool itself, as script is a direct child of the tool.

function onTouch()
    script.Parent:Destroy() -- We want to remove the entire Tool, not just the visible parts in it!
end

-- Binding the function "onTouch" to the Touched-event of 'handle'.
handle.Touched:connect(onTouch)

Ad
Log in to vote
0
Answered by 9 years ago
handle = game.Workspace.Rose.Handle
Part = game.Workspace.Rose.Part--Put these at the top so that the script knows what it is before the function starts.

function OnTouch(hit)
        handle:Destroy()
        Part:Destroy()
end
script.Parent.Touched:connect(onTouch)

Answer this question