Hello! I was trying to create a click to attack script which plays an animation on click. When I made the script, the only thing that didn't seem to work was the function at the bottom of the script. I took it from a tutorial, so I have no idea at all how to fix it. By the way, I'm not using a tool. I'm using an accessory with a union that has an attachment in ServerStorage.
userInputService = game:GetService("UserInputService") print("1") storage = game:GetService("ServerStorage") print("1") scissor = storage.ScissorBlade print("1") plr = script.Parent.Parent.Character print("1") animation = plr.Humanoid:LoadAnimation(scissor.Animation) print("1") userInputService.InputBegan:Connect(function(input, gameProcessedEvent) if input.UserInputType == Enum.UserInputType.MouseButton1 then print("Attack") plr.Humanoid.WalkSpeed = 0 animation:Play() end end)
Those print("1")s were tests to see if the problem was from any of the variables; all 1s printed successfully. Also, "Attack" did not print. If anyone knows how to fix or make this script better, please write an answer, and thank you!
I'm not sure this will answer the question or help but, You can't access the Server storage from the client, try using replicated storage instead of Server storage https://developer.roblox.com/en-us/api-reference/class/ServerStorage Also instead of doing
plr = script.Parent.Parent.Character
do
local Character = game.Players.LocaPlayer -- capitalization may not be correct
And if you want the input function to appear for everyone, use a remote function or event so it happens on the server since it's only on your client.
Hopefully, this helped a little bit