local UIS = game:GetService("UserInputService") local player = game.Players.LocalPlayer local rp = game:GetService("ReplicatedStorage") local Spin = rp:WaitForChild("RESpin") local debounce = false local cooldown = 1 Tool = script.Parent UIS.InputBegan:Connect(function(input,isTyping) if not isTyping then if input.KeyCode == Enum.KeyCode.E and Tool.Equipped == true then if debounce == false then debounce = true Spin:FireServer() end end end end) Spin.OnClientEvent:Connect(function() wait(cooldown) debounce = false end)
Ive tried alot of methods including Tool.Equipped:Connect(function() but none of them work
What you can is hook up a boolean value to the Tool and from there you can set the value to true if the tool is equipped by using the Equipped event and set to false by using the Unequipped event. Later on you can check from the KeyBind input source if this value is true.
This boolean value can be either a physical boolean value (However you would want to manage it from a ServerSided scripts with some remote events hooked up) or Making a local variable to work with (On the client)… Another option is creating an attribute for the Instance however i would suggest choosing from two above.
I highly suggest using ContextActionService as it was made for this exact purpose: binding and unbinding keys to actions. You could bind your button of choosing that will trigger your move when the player equips the tool, then unbind the action when the player unequips the tool.
How would I hook up remote events with a Server sided scripts? cant you only do it on local scripts.
I dont no why this doesnt work I should be using ContextActionService correctly
local contextActionService = game:GetService("ContextActionService") local player = game.Players.LocalPlayer local rp = game:GetService("ReplicatedStorage") local Spin = rp:WaitForChild("RESpin") local spinAction = "Spin" local tool = script.Parent local debounce = false local cooldown = 1 local function SpinFunction() print("works") --if debounce == false then --debounce = true --Spin:FireServer() end local function handleAction(actionName, inputState, inputObject) if actionName == spinAction and inputState == Enum.UserInputState.Begin then SpinFunction() end end tool.Equipped:Connect(function() contextActionService:BindAction(spinAction, handleAction, true, Enum.KeyCode.E) end) tool.Unequipped:Connect(function() contextActionService:UnbindAction(spinAction) end) --Spin.OnClientEvent:Connect(function() --wait(cooldown) --debounce = false --end)