My Server Script acting funny

When I click play my script works perfectly fine. Then once I stop playing it then doesn’t work at all and literally zero errors as if it never existed. How could I fix this problem?

My Code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")


local ButtonInfoModule = require(ServerScriptService:WaitForChild("ButtonInfo"))
local HeldFolders = ReplicatedStorage:WaitForChild("HeldFolders")


local Tycoon = script.Parent.Parent

local DataInfo = Tycoon:WaitForChild("DataInfo")


local function Abbreviate(Value)
	local Abbreviations = {"", "K", "M"}

	for i = 1, #Abbreviations do
		if tonumber(Value) < 10^(i*3) then
			return math.floor(Value/((10^((i-1)*3))/100))/(100) .. Abbreviations[i]
		end
	end
end


local CreatedFolder = Instance.new("Folder")

CreatedFolder.Name = "Buttons"
CreatedFolder.Parent = Tycoon


local TweenedInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)

local TweenedGoal = {
	["Color"] = Color3.fromRGB(140, 100, 100)
}


for _,Folder in pairs(HeldFolders:GetChildren()) do
	local TycoonName = Folder:WaitForChild("TycoonName")

	if TycoonName.Value == DataInfo.TycoonName.Value then
		local Buttons = Folder:WaitForChild("Buttons")

		for _,Button in pairs(Buttons:GetChildren()) do
			local Data = Button:WaitForChild("Data")
			local Pad = Button:WaitForChild("Pad")

			Data.ItemName.Value = Button.Name

			if ButtonInfoModule.Info[Data.ItemName.Value] then
				Data.ItemPrice.Value = ButtonInfoModule.Info[Data.ItemName.Value].Price
				Data.Descendant.Value = ButtonInfoModule.Info[Data.ItemName.Value].Descendant
			end

			Pad.Display.ItemName.Text = Data.ItemName.Value
			Pad.Display.ItemPrice.Text = "Buy - " .. "$" .. Abbreviate(Data.ItemPrice.Value)

			if Data.ItemName.Value == "Dropper 1" then
				print("YES")
				Button.Parent = CreatedFolder
			end
		end
	end
end


--[[for _,Button in pairs(CreatedFolder:GetChildren()) do
	local Data = Button:WaitForChild("Data")
	local Pad = Button:WaitForChild("Pad")

	Pad.Touched:Connect(function(Touched)
		local Player = Players:GetPlayerFromCharacter(Touched.Parent)

		if Player then
			if Player:IsA("Player") then
				local CollectedData = Player:WaitForChild("CollectedData")

				if DataInfo.Claim.Value == true then
					if DataInfo.Owner.Value == Player.Name then
						local CollectedData = Player:WaitForChild("CollectedData")

						if CollectedData.Collected.Value < Data.ItemPrice.Value then
							local CreatedTween = TweenService:Create(Pad, TweenedInfo, TweenedGoal)

							CreatedTween:Play()

						elseif CollectedData.Collected.Value >= Data.ItemPrice.Value then
							for i = 0, 1, 0.25 do
								Pad.Transparency = i
								Pad:WaitForChild("BillboardGui").TextLabel.TextTransparency = i

								task.wait(0.08)
							end
						end
					end
				end
			end
		end
	end)
end--]]

Ok, hold on, when you say ‘playing’ do you mean pressing play on roblox studio? and when you stop you mean pressing stop on roblox studio? If so, then that’s how it should be.

2 Likes

Yes. Through Roblox Studios. To better explain for you. The object doesn’t appear in the game once I press play at curtain times and other times it does.