local contextac = game:GetService("ContextActionService")
script.Parent.Equipped:Connect(function()
script.Parent.Setup:FireServer()
local function inputHandler(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
if actionName == "Shot" then
script.Parent.RemoteEvent:FireServer()
end
end
end
contextac:BindAction("Shot", inputHandler, false, Enum.UserInputType.MouseButton1)
end)
local denounce = false
script.Parent.Equipped:Connect(function()
if denounce == false then
debouce = true
script.Parent.Setup:FireServer()
local function inputHandler(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
if actionName == "Shot" then
script.Parent.RemoteEvent:FireServer()
end
end
end
contextac:BindAction("Shot", inputHandler, false, Enum.UserInputType.MouseButton1)
debouce = false
end
end)
This doesnt help. It happens when I equip and unequip the tool. I think it has something to do with the RemoteEvent being inside another RemoteEvent but i dont know what to do to fix it.
You connect to the RemoteEvent’s OnServerEvent event again each time Setup is fired. So the second time you equip it will print twice, then the next time it will print three times, etc.
Define it once, outside of the setup event. Or disconnect it in response to an anti-setup event.
Another event, probably called Clear or Reset or something, just like the setup one.
Store the connection in a variable, and disconnect with the clear event.
local connection
script.Parent.Setup.OnServerEvent:Connect(function()
print("Setup")
if connection and connection.Connected then
connection:Disconnect()
end
connection = script.Parent.RemoteEvent.OnServerEvent:Connect(function()
print("Shot")
end)
end)
script.Parent.Reset.OnServerEvent:Connect(function()
print("Reset")
if connection and connection.Connected then
connection:Disconnect()
end
connection = nil
end)
Sometimes the studio tends to bug out on me especially in team create it tends to make 2 copies and runs the code twice. I happen to encounter this bug if the studio is open for a long time and restarting the studio usually fixes it. I hope this will help you.