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

Click to attack script doesn't work, for some reason it just stops?

Asked by 4 years ago
Edited 4 years ago

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!

0
Was "Attack" printed Soban06 410 — 4y
0
No YoureTotallyScrewed 9 — 4y
0
Sorry for not including that, I'll edit it in now. YoureTotallyScrewed 9 — 4y
0
Humanoid:LoadAnimation() is deprecated. Did you use a localscript or a serverscript? Also why did you put this in ServerStorage? Dovydas1118 1495 — 4y
0
I'm just using a normal Script. Sorry if normal isn't a very good description, I don't know too much Lua vocabulary.. YoureTotallyScrewed 9 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Ad

Answer this question