I need help because im trying to create Weight Lifting Simulator game And my code is
local UserInputService = game:GetService("UserInputService") local Tool = script.Parent local Animation = script.Parent.OnClick UserInputService.InputBegan:Connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then Animation:Play() end end)
Tools are objects that a Humanoid object can equip. For players, they are stored in a Backpack object parented to a Player object.
In-game, players may have multiple tools which appear as icons at the bottom of the screen.
Equipping a tool moves it from the Backpack and into a player’s Character|character model in the Workspace. By default, tools are held in the right hand and have a handle in them, which is a Part named “Handle” inside (though one is not required if Tool.RequiresHandle is off). Tools that are to be provided to (re)spawning players ought to be stored in the StarterPack.
On desktop, pressing a number key (1, 2, 3…) will equip a tool. Equipped tools can be dropped into the Workspace by pressing Backspace.
It’s recommended that you turn Tool.CanBeDropped off so it is not possible to drop a tool, die, respawn and drop again to duplicate tools. On gamepads, LB and RB buttons will equip tools. You can disable activation via left click (or right trigger on gamepad) by setting Tool.ManualActivationOnly on. Doing so requires that you call Activate yourself through some sort of other user input.
Tools are not the only way to capture user input.
You can also use ContextActionService, UserInputService or Player:GetMouse If you need a Tool to have multiple actions, such as pressing a key while the Tool is equipped.
You should use ContextActionService’s BindAction and UnbindAction in the Equipped and Unequipped events, respectively. Use a LocalScript send these actions to the server via. a RemoteFunction inside the Tool.
-- Some of it from the wiki
.Activated
.Equipped
.Unequipped
.Deactivated
All of these samples are events, which are most commonly used, or another-words always used in tool events;
The Activated event fires when the player clicks while a Tool is equipped.
This function is used to perform an action when the player uses the tool. For instance, when the player clicks while a Rocket Launcher tool is equipped, the activated event executes the code to create and launch a rocket.
Insert a script in the Tool, paste the script below which will determine the current state;
local Tool = script.Parent Tool.Activated:Connect(function() print("I was clicked!") end)
Animations truly bring a game to life. From easily-accessible character animations in the catalog to detailed animations built with the Animation Editor, Roblox offers a variety of powerful animation options.
By default, Roblox player characters include common animations like running, climbing, swimming, and jumping. However, these animations are not locked in place — if desired, you can replace them with catalog animations or even load in your own custom animations.
To use a custom animation exported from the Animation Editor, locate its asset ID as follows:
Controls the playback of an animation on a Humanoid or AnimationController. This object cannot be created, instead it is returned by the Humanoid:LoadAnimation method.
I'm assuming you already have your animation; Insert a local-script in your tool;
local Tool = script.Parent local Player = game.Players.LocalPlayer repeat wait() until Player.Character ~= nil function Activate() local Animation = script.Parent.OnClick if Player.Character then local Character = Player.Character if Character:FindFirstChild("Humanoid") then local Hum = Character.Humanoid local AnimationTrack = Hum:LoadAnimation(Animation) AnimationTrack.Priority = Enum.AnimationPriority.Action AnimationTrack:Play() end end end Tool.Activated:Connect(Activate)
Your script is mostly correct, except you don't define what humanoid you're playing the animation on.
local UserInputService = game:GetService("UserInputService") local Tool = script.Parent local Animation = script.Parent.OnClick local animTrack = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(Animation) UserInputService.InputBegan:Connect(function(InputObject) if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then animTrack:Play() end end)
Please note that this script will only work from a local script.