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

How do I make a script in a tool work properly, functioning client-sided and server-sided?

Me and my friend are working on a game. It's magic themed and one of the things are wands - I'm trying to script it but it doesn't seem to do anything. For this script, I am making a function where when you press Q on your keyboard while you have your wand equipped, you do a block animation and block any incoming spells (for now it just prints to check if everything is working). When I run it, it does not work. No errors are in console, but nothing happens, it doesn't print anything.

Script:

local enabled = false
local uis = game:GetService("UserInputService")

--variables

script.Parent.Parent.Equipped:Connect(function()
	enabled = true
end)

script.Parent.Parent.Unequipped:Connect(function()
	enabled = false
end)

--yanno

uis.InputEnded:Connect(function(input)
	if input == Enum.KeyCode.Q and enabled == true then
		print("working")
	end
end)

https://gyazo.com/3d7c58bff77f7fde594344d343e10d6d

1 answer

✓ Accepted answer

Put your script in a LocalScript instead of a Script...

and change input to input.KeyCode on line 17

So the whole code looks like this

--    ////// WRITE THIS IN A LOCALSCRIPT ////// --

local enabled = false
local uis = game:GetService("UserInputService")

--variables

script.Parent.Parent.Equipped:Connect(function()
    enabled = true
end)

script.Parent.Parent.Unequipped:Connect(function()
    enabled = false
end)

--yanno

uis.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Q and enabled == true then --this changed
        print("working")
    end
end)

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