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

I have a few questions about the tool object, can anyone answer them?

Asked by 4 years ago
Edited 4 years ago

So recently I was making this toolbox game so I can grab stuff I've made by myself so I don't just have to create it all over again. I have been making some tools in the collection, and I have some questions on the tool object.

  1. If I put a script in a tool, how would I refer to the character or player? (either one is fine)
  2. If I was creating an animation and had it so whenever I touched a certain key, it would play, and the tool was equipped, would the tool move with the arms in the animation?

If you can answer these questions, I would be so happy! Thanks.

0
@jadenroblox2000, to refence the character you could do script.Parent or script.Parent.Parent because the tool itself should be inside the character when equipped and inside the backpack when unequipped. for 2, make sure no handle is required and then load the animation into humanooid and play it. You can directly test it. BlackOrange3343 2676 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
  1. You would call it by: a. Calling it in a localscript by game.Players.LocalPlayer. b. From a normal script, if it was in the players hand, you would do game.Players:FindFirstChild(tool.Parent.Name) or if it was just in their backpack: tool.Parent.Parent

  2. The tool would move with the animation, staying on the hand.

(Please accept if this helped you!)

Ad
Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Question One

From a localscript you can get the player by saying:

player = game.Players.LocalPlayer

Get the character by saying:

player = game.Players.LocalPlayer
repeat wait() until player.Character
character = player.Character

From a normal script it's a bit different. There is no concept of a local player because the script runs on the server not the client. The server only knows it has a bunch of players in it.

You can get a player, but only through roblox's built in events or through remote events.

Never tried getting a player through remote events. Don't think you'd ever need to.

If you want to get a player when you're touching a brick for example, you'd do the following:

part = game.Workspace.Part

part.Touched:Connect(function (hit)
       --see if the thing touching our part is a player
       local player = game.Players:FindFirstChild(hit.Parent.Name)

        --if it is a player get it's character and tool
        if(player)then
               local character = hit.Parent 
                local tool = character:FindFirstChildWhichIsA("Tool")
       end 
end)

Question Two:

Yes, you can even play both animations at once if you'd like.

0
An easier more effective way to get the character in a local script is: local char = plr.Character or plr.CharacterAdded:Wait() Eagle0022 75 — 4y
0
@Eagle0022 both are as effective, @royaltoe i think he meant server script. BlackOrange3343 2676 — 4y
0
server script for which bit? royaltoe 5144 — 4y
0
I explained how to do both royaltoe 5144 — 4y
0
Pls respond royaltoe 5144 — 4y

Answer this question