Is there anybody know how to make animation when player click on mouse?
Without tool
Is there anybody know how to make animation when player click on mouse?
Without tool
To detect when players click their mouse, you can use the Mouse object
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Mouse.Button1Down:Connect(function()
-- code here
end)
or you can use UserInputService.
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
-- code here
end
end)
Since this is handled in the client, you can use this in a LocalScript parented to anything associated with the player.
Where Should i put the script?
StarterGui, StarterPack, StarterPlayerScripts, StarterCharacterScripts, ReplicatedFirst.
I personally like putting scripts like these in StarterPlayerScripts unless they’re closely related to the character, then I put them in StarterCharacterScripts.
why is the script not working?
local UserInputService = game:GetService(“UserInputService”)
UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
local animation = Instance.new(“Animation”)
animation.AnimationId = “7330349933”
end
end)
Am i wrote everything right?
I am just Newbie
Be sure that your written code, is a in local script.
You need to play the animation.
e.g.
local player = game:GetService('Players').LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild('Humanoid')
local UIS = game:GetService('UserInputService')
UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local animator = hum:FindFirstChild('Animator')
if animator then
local anim = Instance.new('Animation')
anim.AnimationId = 'rbxassetid://IDHERE'
local animTrack = animator:LoadAnimation(anim)
animTrack:Play()
end
end
end)
This is still don’t play the animation
Ah oops, I accidentally wrote the script without using the humanoid; give me a second.
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
UIS.InputBegan.Connect(function(input, isTyping)
if isTyping then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local anim = Instance.new('Animation')
anim.Parent = "Your anim's location" -- You need to give location for your animation
anim.AnimationId = 'rbxassetid://IDHERE'
local track = Humanoid:LoadAnimation(anim)
track:Play()
end
end)
Maybe try this…
put this in StarterCharacterScripts btw or it won’t work when your character respawns
I have fixed the script, it should be updated now.
Sorry but this is still not working
Its finally working! Thank you so much
And thanks to other who tried to help me