I made a script that when the player equips the tool and has their button1down, it fires a remote and spawns parts in front of them and sendings true, but when the player lets go of button1 the script is supposed to delete the parts in front of them but it doesnt?
For starters I would recommend using UserInputService, as I believe those events of the mouse object is deprecated, and this is unconfirmed but the entire mouse object could possibly be deprecated as well.
So your events would be the same as:
local uis = game:GetService("UserInputService")
local mouse_down = false
uis.InputBegan:Connect(function(input, g)
if not g and input.UserInputType == Enum.UserInputType.MouseButton1 then
mouse_down = true
end
end)
uis.InputEnded:Connect(function(input, g)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
mouse_down = false
end
end
Other than this, I’m sort of struggling to understand what your code is doing. If you could provide more details as to what the code does, and what it isn’t doing, and more on the goal, I may be able to help you further.
I just looked at your code again, and I believe the issue is because you’re running a while loop on the parameter of the event:
while holding
Here’s the issue with that. Each time you fire a call to a server remote like this, it creates a new process of that body of code. It won’t run hand and hand, if that makes sense. So from my perspective, I’d think that loop would run forever, because if I call into the server with a ‘true’ parameter, that loop will never stop running, and the more calls I make to the server most likely the laggier the game will become and you can probably expect weird things to occur.
Hope this helps a bit, I can try to work with your code a bit to provide an actual solution.
You also have no reason to be calling OnServerEvent twice for the same remote object. Seems like you are just overthinking it a little bit. You shouldnt even have to pass “Holding” into the remote aswell since its either “on” or “off” if that makes sense.
The whole “Holding” thing seems to be redundant, check if the user has these spawned “objects” and delete them if they do. Otherwise spawn them in.