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

How can I make a tool be dropped using a script?

Asked by 9 years ago

Hello! I am currently working on a boomerang tool. I haven't gotten too far but I have an idea of where it is going. So basically when the player clicks the boomerang will use a BodyPosition to go away from the player. But I am stuck; I want the tool to be "dropped". Or basically removed form the player's inventory but not completely removed, Just placed into the workspace. I don't know how I can do this though.

Tool = script.Parent

function onActivated()
    Tool.Handle.BodyPosition.Position = Tool.Parent.Parent.Torso + Vector3.new (20,0,0)
    --This is where I want the tool to be taken out of the players inventory and placed into the workspace but I don't know how.
end

Thanks! ~Minikitkat

0
The reason that dyler's script doesn't work is because (I know it's stupid but it's ROBLOX) BodyPosition.position isn't accessible for some stupid reason, unless the instance is created within that script. So instead you have to create a value (not using Vector3) for x,y,z and then reference that to move it =/ BSIncorporated 640 — 9y

1 answer

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
9 years ago

Just do this:

Tool = script.Parent

function onActivated()
    wait()
    Tool.Handle.BodyPosition.position = Tool.Parent.Torso.Position + Vector3.new (20,0,0)
    Tool.Parent=game.Workspace
end

Tool.Equipped:connect(onActivated) --Connects the function

This will remove it from the player, and place it in the Workspace, and in effect, it will be dropped. If you have any questions or problems, please leave a comment below. Hope I helped :P

More efficient function use:

Tool = script.Parent

Tool.Equipped:connect(function() --Same thing as the other, just simpler, and harder to forget.
    wait()
    Tool.Handle.BodyPosition.position = Tool.Parent.Torso.Position + Vector3.new (20,0,0)
    Tool.Parent=game.Workspace
end) --You NEED this closing parenthesis to close the function at the end if you use this method.

Just an example. I suggest you start practicing this way, it's a better way of calling and connecting functions :P

0
No this didn't work. I tried this already and nothing happens. You would think it would work but it doesn't. any other suggestions? minikitkat 687 — 9y
0
DERP. I always forget to connect it. Thanks!! minikitkat 687 — 9y
0
Lol, no prob. Just a suggestion, but you might want to try learning the more efficient method for functions. I'll go ahead and leave an example of what I mean in the post. dyler3 1510 — 9y
Ad

Answer this question