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

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

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.

1 comment

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.

2 answers

  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!)

#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.

5 comments

0

An easier more effective way to get the character in a local script is: local char = plr.Character or plr.CharacterAdded:Wait()

0

@Eagle0022 both are as effective, @royaltoe i think he meant server script.

0

server script for which bit?

0

I explained how to do both

0

Pls respond

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