-
What do you want to achieve? A script that when you click
Q
and then use your mouse to click on a player or a burnable object it will fire to the server and then handle all the effects in the server -
What is the issue? the script I have is spammable. They can click Q a bunch of times and the click on a player or object and it’ll fire the remote more than once which is what I want to get rid of
-
What solutions have you tried so far? I have tried using debounces, disconnecting the connection as soon as possible but nothing has worked
here’s the whole script
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local WorkspaceService = game:GetService("Workspace")
local player = game.Players.LocalPlayer
local character = player.Character
local currentCamera = workspace.CurrentCamera
local mouse = player:GetMouse()
local Event = ReplicatedStorage.WitchRemotes:FindFirstChild("Pyrokinesis")
local debounce = false
local connection
local function getMouseHit()
local mouseLocation = UserInputService:GetMouseLocation()
local viewportPointRay = currentCamera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y)
local extendedRay = Ray.new(viewportPointRay.Origin, viewportPointRay.Direction * 1000)
return WorkspaceService:FindPartOnRay(extendedRay)
end
UserInputService.InputBegan:Connect(function(input, processed)
if input.KeyCode == Enum.KeyCode.Q and not debounce then
connection = mouse.Button1Down:Connect(function()
debounce = true
connection:Disconnect()
local hit, position, normal = getMouseHit()
if hit and hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent == character then return end
local distance = math.abs(hit.Parent.HumanoidRootPart.Position.Magnitude - character.HumanoidRootPart.Position.Magnitude)
if distance <= 10 then
debounce = true
print("Player")
Event:FireServer("Player", hit.Parent)
task.wait(1)
debounce = false
end
elseif hit and hit:FindFirstChild("CanBurn") then
local distance = math.abs(hit.Position.Magnitude - character.HumanoidRootPart.Position.Magnitude)
if distance <= 10 then
debounce = true
print("Object")
Event:FireServer("Object", hit)
task.wait(1)
debounce = false
end
end
end
end)
elseif input.KeyCode == Enum.KeyCode.Q and debounce == true then
return
end
end)
all help is appreciated