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.
Basically when the player holds m1, parts spawn in and it follows the player, but when they let go of m1, theyāre supposed be destroyed in this line.
script.Roar.OnServerEvent:Connect(function(plr,holding)
if holding == false then
for i,v in pairs (_G.parts[plr]) do
v:Destroy()
end
end
end)
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.