Basically I’m trying to make it so when the player types /e invert their game gets inverted. It works and you can fix the invert but then you can’t use the invert again. (Not Intentional)
How do I make it so it can be used again?
task.wait()
InvEvent = game.ReplicatedStorage.Events.Invert
Con = InvEvent.OnClientEvent:Connect(function()
if workspace:FindFirstChild("InvertHighlight") == nil then
script.Parent:Clone().Parent = workspace
Con:Disconnect()
else
workspace:FindFirstChild("InvertHighlight"):Destroy()
--Con:Disconnect()
end
end)
You will need to reconnect the connection after disconnecting it, or else it will not run the function again. Is there any reason why you need to disconnect the connection? It seems like it would work fine without it.
When you do this, it clones the script as well. This is likely the cause of your issue. Try deleting or disabling the script before you parent the clone to the workspace.
Bob may be right here. Perhaps have a bool and state not inverted each time the event is triggered. It is a lot less memory heavy and a lot simpler to understand.
task.wait()
InvEvent = game.ReplicatedStorage.Events.Invert
Con = InvEvent.OnClientEvent:Connect(function()
if workspace:FindFirstChild("InvertHighlight") == nil then
local hlight = script.Parent:Clone()
hlight.Invert:Destroy()
hlight.Parent = workspace
else
workspace:FindFirstChild("InvertHighlight"):Destroy()
end
end)