I made a camera parallax script for the main menu of my game. It works fine and updates each time the mouse is moved.
The loading screen is handled by a LocalScript which also controls the camera. Here’s the code:
Basically, whenever the LocalScript is deleted or disabled, this code bit continues to run.
I’ve tried incorporating an if-then statement (if script.DisableParallax.Value == false then & while script.DisableParallax.Value == false do), however these don’t make any difference.
There’s no errors, and it runs as if it were to never had been deleted.
I’ve been trying to fix this for several hours with a few breaks between.
I really thought that would work. I’ll have to look into it some more, I’ll let you know what I find.
Update:
So I’ve just made some sample code below, and after 5 seconds, the code inside the move function stops firing.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local connection
connection = mouse.Move:Connect(function()
print("hi")
end)
wait(5)
print("disconnecting function")
connection:Disconnect()
Is it possible that you have another script doing the exact same thing?
Put this code into a screen gui on a new baseplate. It should stop firing after the 5 seconds are up.
It still shows that the button was clicked (output below) despite not Disconnecting.
By the way, I really appreciate the help! Also, it’s getting late so I should get to sleep, I will be back in the morning (For the record, I’m back now)
It prints as expected, however, the Mouse.Move function continues to run after being ‘disconnected’ (it still prints “a” every time the mouse moves although the output reads that the function was disconnected).
This is interesting, why would you need an event for the disconnect, if you can just disconnect the event when the button is clicked? I see your Disconnect event as unnecessary.
I tried integrating what you had sent me even if it seemed a bit unreasonable, for some reason just Disconnecting from clicking the button doesn’t work. There’s no error, it runs through the code, however the code it was supposed to stop continues running as well.