I am testing something that can stop a function, but it is not working .
here is a server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local StartQuestRemote = ReplicatedStorage:WaitForChild("StartTheQuest")
local GiveMoneyRemote = ReplicatedStorage:WaitForChild("GiveMoney")
local StopQuestRemote = ReplicatedStorage:WaitForChild("StopTheQuest")
local Module = require(ServerStorage:WaitForChild("ModuleScript"))
StartQuestRemote.OnServerEvent:Connect(function(Player,StartOrStop)
if StartOrStop == "Start" then
Module.StartTask1(Player)
elseif StartOrStop == "Stop" then
Module.StartTask1:Destroy()
end
print("QuestStarted")
end)
here is a Module script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local StartQuestRemote = ReplicatedStorage:WaitForChild("StartTheQuest")
local GiveMoneyRemote = ReplicatedStorage:WaitForChild("GiveMoney")
local StopQuestRemote = ReplicatedStorage:WaitForChild("StopTheQuest")
local Module = require(ServerStorage:WaitForChild("ModuleScript"))
StartQuestRemote.OnServerEvent:Connect(function(Player,StartOrStop)
if StartOrStop == "Start" then
Module.StartTask1(Player)
elseif StartOrStop == "Stop" then
Module.StartTask1:Destroy()
end
print("QuestStarted")
end)
here is a Local script
local GiveMoneyButton = script.Parent.GiveMoneyButton
local StartQuestButton = script.Parent.StartQuestButton
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GiveMoneyRemote = ReplicatedStorage:WaitForChild("GiveMoney")
local StartQuestRemote = ReplicatedStorage:WaitForChild("StartTheQuest")
local StopQuestButton = script.Parent.StopQuestButton
GiveMoneyButton.MouseButton1Click:Connect(function()
GiveMoneyRemote:FireServer()
end)
StartQuestButton.MouseButton1Click:Connect(function()
StartQuestRemote:FireServer("Start")
end)
StopQuestButton.MouseButton1Click:Connect(function()
StartQuestRemote:FireServer("Stop")
end)
StartQuestRemote.OnServerEvent:Connect(function(Player,StartOrStop)
local PlayerMoney = Player:WaitForChild("leaderstats").Money
local Task1Event
if StartOrStop == "Start" then
Task1Event = PlayerMoney.Changed:Connect(function()
print(PlayerMoney.Value," Changed")
end)
elseif StartOrStop == "Stop" then
Task1Event:Disconnect()
end
end)
I would try to have the StartQuestRemote, the one that gets disconnected.
or
StartQuestRemote.OnServerEvent:Connect(function(Player,StartOrStop)
local PlayerMoney = Player:WaitForChild("leaderstats").Money
local Task1Event
if StartOrStop == "Start" then
local function PlayerMoney()
print(PlayerMoney.Value," Changed")
end
Task1Event = PlayerMoney.Changed:Connect(PlayerMoney)
elseif StartOrStop == "Stop" then
return
end
end)
I don’t really know if that will work, I feel like I’m missing something, if all else fails try to use return instead of Disconnect also I