i need it to be in a normal script for this to work but they keydown function only seems to work in a local script
does anyone know why it only works in a local script?
--//Keystroke class local debounce = true script.Parent.Equipped:Connect(function() local tool = script.Parent local char = tool.Parent local player = game.Players:GetPlayerFromCharacter(char) local mouse = player:GetMouse() local v = script:WaitForChild('Value') mouse.KeyDown:Connect(function(key) print (key) -- stuff end) end)
You cannot get the player's mouse in a Server Script. You can use a RemoteEvent for this to work.
Local Script:
--//Keystroke class local debounce = true script.Parent.Equipped:Connect(function() local tool = script.Parent local char = tool.Parent local player = game.Players:GetPlayerFromCharacter(char) local mouse = player:GetMouse() local RemoteEvent = game.ReplicatedStorage.RemoteEvent local v = script:WaitForChild('Value') mouse.KeyDown:Connect(function(key) RemoteEvent:FireServer(key) end) end)
Server Script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, Key) --Code print(Key) end)
Let me know if it doesn't work. I'll try to help you.