This post is a followup to this post: (Help with :ClearAllChildren() and RemoteEvents) which is part one to the issues of a placement system. As resolved in that post, the cones now get deleted however WHENEVER the “R” key is pressed, not just when the tool is equipped. Even when chatting it still does this. I have tried multiple methods such as a debounce and Tool.Activated but neither methods work.
Help would be appreciated! Snippets of the code can be found below. (Only parts relating to the deletion of cones!)
local UIS = game:GetService("UserInputService")
local Tool = script.Parent
Tool.Equipped:Connect(function()
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
game.ReplicatedStorage.ClearCone:FireServer()
end
end)
end)
local UIS = game:GetService("UserInputService")
local Tool = script.Parent
Tool.Equipped:Connect(function()
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.R then
game.ReplicatedStorage.ClearCone:FireServer()
end
end)
end
Make a function for what you want to happen when r is pressed.
When the tool is equipped, use ContextActionService:BindAction(actionName, function, createmobilebuttons, keycode (Enum.KeyCode.R))
When the tool is Unequipped, use ContextActionService:UnbindAction(actionName)
if you’d like to use userinputservice (dont lmao) you need to make a variable that’s set to true when your tool is equipped, and set to false when it’s unequipped, then simply check if that variable is true when the button is pressed (not inside the equipped event)
Really quickly, just curious what the bug was. If the gun was firing twice, that’s because contextactionservice fires when the action starts, AND ends, you can fix this with the arguments that it returns, actionname (you wont need this) and userinputstate
function(actionname, state)
now just check if the state is equal to the beginning
if not state == Enum.UserInputState.Begin then return end