Hi
, I’m been working on a
pizza Delivery
game and currently on the ‘Skill system’ thing.
-
What I got currently so far
-
So my idea is using LocalScript for each skill, store it in Player Backpack and only Enable what player Equipped and Disable when player UnEquip it.
-
Let take this simple script as an Example.
-
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("Sound_Remote")
local UIS = game:GetService("UserInputService")
local Connection = UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
Remote:FireServer("Shield")
end
end)
-
What do you want to achieve?
-
I want to optimize the memory usage as much as possible by disconnect all the Connection(s) when the script is Disabled
-
Got the answer for “when the script got disabled, does it auto disconnect the connections in it or its just pause the script and back to running when Enabled”
-
-
What is the issue?
- The problem is, I don’t know how to Disconnect the connections when the script is Disabled… ( . _ . )
-
What solutions have you tried so far?
- I been searching Forum for few days and haven’t find any problem similiar…
- I’ve try to use connect a function that use to disconnect the connection using
:GetPropertyChangedSignal("Disabled")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("Sound_Remote")
local UIS = game:GetService("UserInputService")
local Connection = UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.F then
Remote:FireServer("Shield")
end
end)
-- disconnect when the script is not Enable
script:GetPropertyChangedSignal("Disabled"):Connect(function()
if script.Disabled == true then
print("Disconnected")
Connection:Disconnect()
end
end)
- this is what the script look like
- And… it not working, its doesn’t print anything.
So what I want to know is there any way to disconnect the connections when script disabled or any suggestion on optimize the my system. Thank you very much! ![]()