I’m having an issue where even after a script has been destroyed, the loops inside continues to run.
I’ve tried parenting the script to server storage THEN destroying it, but the outcome is still the same. I’ve also tried adding an if statement inside the loop checking if the folder that the script is in equals a specific name and if it doesn’t then it breaks the loop, but that also doesn’t work either.
I’m new to scripting so if it’s messy or there’s a better way to do it I’m sorry lol
local GrowModule = {}
local function updateGui(player,creature)
local waterGuiModule = require(player.PlayerGui:WaitForChild("PlayerGuiStats"):WaitForChild("Stats"):WaitForChild("Thirst"):WaitForChild("Blue").WaterGuiModule)
local foodGuiModule = require(player.PlayerGui:WaitForChild("PlayerGuiStats"):WaitForChild("Stats"):WaitForChild("Hunger"):WaitForChild("Red").FoodGuiModule)
waterGuiModule.ChangeText(player,creature)
foodGuiModule.ChangeText(player,creature)
end
local function growFunction(player,age,rate,creatureSelected,perc,amber)
local isAdult
if player.Character then
local stage
local model
local pos = player.Character:GetPrimaryPartCFrame()
local teenAmber = rate * 3
local adultAmber = rate * 4
local servCreature = game.ServerStorage:WaitForChild("Assets"):WaitForChild("Morphs"):WaitForChild(creatureSelected)
if age.Value == "Adult" then
isAdult = true
end
if isAdult then return end
perc.Value = 0
local growScript = player.Character.CreatureExtras.Scripts.GrowScript
growScript.Parent = game.ServerStorage.GarbageContainer
growScript:Destroy()
player.Character:Destroy()
if age.Value == "Baby" then
amber.Value = amber.Value + teenAmber
model = servCreature:WaitForChild("Teen"):Clone()
age.Value = "Teen"
elseif age.Value == "Teen" then
amber.Value = amber.Value + adultAmber
model = servCreature:WaitForChild("Adult"):Clone()
age.Value = "Adult"
end
model.Name = player.Name
player.Character = model
model.Parent = workspace.Players
model:SetPrimaryPartCFrame(pos)
local module = require(player.PlayerGui.UserSelectionGui:WaitForChild("GUI_Left").GrowthCombat.GreenContainer.GrowthText.GrowthGuiModule)
updateGui(player,creatureSelected)
module.ChangeText(perc.Value,age.Value)
local nameTagModule = require(game.ServerStorage:WaitForChild("Modules"):WaitForChild("UpdateNameTags"))
nameTagModule.update()
end
end
function GrowModule.percUp(player,age,rate,creature)
if player.Character.Parent.Name == "Players" then
local creatureValues = game.ServerStorage:WaitForChild("ServerPlayerStats"):WaitForChild(player.Name):WaitForChild("CreatureFolder"):WaitForChild(creature)
local perc = creatureValues:WaitForChild(creature.."-Percent")
local servAge = creatureValues:WaitForChild(creature.."-Age")
local amber = creatureValues.Parent:WaitForChild("Amber")
local rateTwo = player.Character.CreatureExtras.Stats.Rate.Value
if perc.Value < 100 then
perc.Value = perc.Value + 1
if perc.Value >= 100 then
growFunction(player,servAge,rateTwo,creature,perc,amber)
end
end
wait(.5)
local guiModule = require(player:WaitForChild("PlayerGui").UserSelectionGui:WaitForChild("GUI_Left").GrowthCombat.GreenContainer.GrowthText.GrowthGuiModule)
guiModule.ChangeText(perc.Value,servAge.Value)
end
end
return GrowModule
I believe when you destroy the player’s character, if GrowScript is located in StarterCharacterScripts, it just gets re-created so maybe you should first destroy the character and then destroy the script, or well… I don’t quite know what you’re going for…
if it’s not the “GrowScript” in question then just let me know which one it is
EDIT: I could be wrong though
Yup, all player’s characters are parented to a folder in workspace called Players, and on both the server and client the orignal player’s character isn’t in there anymore. also there’s no other scripts that mess with these ones either.
There’s a folder in server storage that holds all the creatures models. 3 different sizes with their own respective stats for each creature. In each creature there’s a script folder and the growscript is in there. My players are running into an issue where when you grow then switch to a different creature it continues to increase the original creature’s percentage along with the current creature’s percentage at the same time.
I’ve tried disabling the growscript in the module script once the player grows into the next stage, but it still has the same behavior. Scripting is confusing
I also want to point at that this ONLY started happening when I moved from local scripts and server events to server scripts and modules. I had to switch because exploiters were insta-growing to adult.
The scripts were the same but changed up to require a module instead of firing a server event.
As I mentioned it earlier already, script is only getting parented to nil, but it is still running. In order to break the while loop you could wrap it either in a function and disconnect it or coroutine and pause it.