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

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

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!

5 comments

0

Was "Attack" printed

0

No

0

Sorry for not including that, I'll edit it in now.

0

Humanoid:LoadAnimation() is deprecated. Did you use a localscript or a serverscript? Also why did you put this in ServerStorage?

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

1 answer

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

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