Script not working correctly

Sorry if this is vague but I am extremely delirious right now.

This script just isn’t working and I don’t know why.


		local Trade = Instance.new("Model")
		local Check = game.ReplicatedStorage.Trading:FindFirstChild(Trade.Name)
		local Id = math.random(1, 10000000)
		Trade.Name = "Trade" .. tostring(Id)
		repeat
			if Check then
				Id = math.random(1, 10000000)
				Trade.Name = "Trade" .. tostring(Id)
				Trade.Parent = game.ReplicatedStorage.Trading
				local Check = game.ReplicatedStorage.Trading:FindFirstChild(Trade.Name)
			else
				Trade.Parent = game.ReplicatedStorage.Trading
			end
			wait(0.1)
		until Check == false
		script.Parent.Parent.Value.Changed:Connect(function()
			print("hey")
			if script.Parent.Parent.Value.Value ~= nil then
				print("yo")
				Id = script.Parent.Parent.Parent.TradeId.Value
				local Trader1 = Instance.new("StringValue")
				Trader1.Parent = game.ReplicatedStorage.Trading("Trade" .. tostring(Id))
				Trader1.Name = script.Parent.Parent.Value.Value
				local Trader2 = Instance.new("StringValue")
				Trader2.Parent = game.ReplicatedStorage.Trading("Trade" .. tostring(Id))
				Trader2.Name = script.Parent.Parent.Parent.Parent.Parent.Name
				script.Parent.Parent.Parent.Parent.Fish.Trade.TradeAccept.TradeId.Value = Id
			end			

No output, for some reason.

image
This is the script

Thanks.

Haven’t looked into the script, but I can see a ServerScript inside a GUI which is usually ran by the client. Have you tried a LocalScript for things not ran by the server?

local Storage = game:GetService("ReplicatedStorage")
local Trade = Instance.new("Model")
Trade.Parent = Storage
local Trading = Storage:WaitForChild("Trading")
local Check = Trading:FindFirstChild(Trade.Name)
local Id = math.random(1, 10000000)
Trade.Name = "Trade"..Id

repeat
	if Check then
		Id = math.random(1, 10000000)
		Trade.Name = "Trade"..Id
		Trade.Parent = Trading
		local Check = Trading:FindFirstChild(Trade.Name)
	else
		Trade.Parent = Trading
	end
	task.wait(0.1)
until not Check

script.Parent.Parent.Value.Changed:Connect(function()
	if script.Parent.Parent.Value.Value ~= nil then
		Id = script.Parent.Parent.Parent.TradeId.Value
		local Trader1 = Instance.new("StringValue")
		Trader1.Parent = Trading["Trade"..Id]
		Trader1.Name = script.Parent.Parent.Value.Value
		local Trader2 = Instance.new("StringValue")
		Trader2.Parent = Trading["Trade"..Id]
		Trader2.Name = script.Parent.Parent.Parent.Parent.Parent.Name
		script.Parent.Parent.Parent.Parent.Fish.Trade.TradeAccept.TradeId.Value = Id
	end
end)

Is this what you were trying to achieve? It’s hard to discern the purpose of the script without much context.
Just so you know in the repeat loop “Check” will always evaluate to true so it will cycle infinitely. You’re setting the name of the model named “Trade” and some ID and then checking if a child can be found of that same name in the folder named “Trading” because of this Check will always represent a Boolean value of true and thus the repeat loop will never break.

Please use localscripts inside the startergui and use server scripts in the server script service or workspace.

Again, sorry for being vague. I’m pretty sure I found a solution to this problem, the loop was the culprit and it didn’t allow the rest of the script to function. Thanks for helping.