Comparison to my code and Chat gpt

Im not sure if this relevant, so bear with me. I’ve been coding legitimately for about 1-2 months. And during this time I had the necessary knowledge to make a trail system, which I was almost finished with. Then I came across a problem, I couldn’t figure out how to make an equip and unequip work, so I asked what chat gpt thought of it when I first heard about it, and I asked it to fix my code. I will tell that I was surprised, little after reading it and applying it, the code chat gpt revised worked perfectly, which made me very discouraged, and I’m not sure what to say, maybe I can learn from this experience.

Here’s my code for equipping

local repstorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local equipped = false


for index, value in pairs(script.Parent.TrailFolder:GetChildren()) do
	if value:IsA("TextButton") then
		value.MouseButton1Click:Connect(function()
			
			if player.leaderstats.Coins.Value >= value.Price.Value and equipped == false then
				value.Text = "Equipped"
				equipped = true
				repstorage.TrailRemote:FireServer(value.Name, equipped)
			else
				if equipped == true then
					equipped = false
					value.Text = "Equip"
					repstorage.TrailRemote:FireServer(value.Name, equipped)
				end
			end
		end)
	end
end

Chat gpt code for equipping

local repstorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer

for index, value in pairs(script.Parent.TrailFolder:GetChildren()) do
	if value:IsA("TextButton") then
		value.MouseButton1Click:Connect(function()
			if player.leaderstats.Coins.Value >= value.Price.Value then
				-- If the button is already equipped, unequip it
				if value.Text == "Equipped" then
					value.Text = "Equip"
					value.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
					repstorage.TrailRemote:FireServer(value.Name)
				else
					-- Reset the text and appearance of all buttons
					for _, button in pairs(script.Parent.TrailFolder:GetChildren()) do
						if button:IsA("TextButton") then
							button.Text = "Equip"
							button.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
						end
					end
					-- Set the text and appearance of the clicked button
					value.Text = "Equipped"
					value.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
					-- Fire the TrailRemote object with the name of the clicked button as a parameter
					repstorage.TrailRemote:FireServer(value.Name)
				end
			end
		end)
	end
end

Although after reading its not hard to understand, I was just very discouraged that I couldn’t figure it out. I just want to know what you guys think and maybe give some encouragement to keep going.

Although I’m discourage, I want to encourage you guys to never give up, I know it sounds cliché, but its true.

2 Likes

–server side

local repstorage = game:GetService(“ReplicatedStorage”)
repstorage.TrailRemote.OnServerEvent:Connect(function(player, trail, equipped)
local trail = repstorage.Trail:FindFirstChild(trail)
if equipped == true then
for index, value in pairs(repstorage.Trail:GetChildren()) do
if player.Trail.Value == “None” then
value.ImageColor3 = Color3.fromRGB(255, 255, 255)
else
value.ImageColor3 = Color3.fromRGB(255, 255, 255)
end
end
trail.ImageColor3 = Color3.fromRGB(0, 255, 0)
player.Trail.Value = trail.Name
print(trail.Name)
else
trail.ImageColor3 = Color3.fromRGB(255, 255, 255)
player.Trail.Value = “None”
end
end)

UPDATE

So after a little more research, I’ve managed to get my equip and unequip working. Thank you for your help @ZackeryWatson.

This is a fairly common mistake. You’re trying to use a local variable across multiple events.
local equipped = false
This is false for the current event, but it’s also false for all other events.
You need to use a different variable for each event.
local equipped = false
value.MouseButton1Click:Connect(function()
local equipped = false
–rest of code
end)

Do this for each event that you want to operate independently.

chat Gpt can never replace the actual devs because it can only give you simple codes and sometimes they don’t give the full code also

1 Like

Sorry for late response, but yeah I’ve been trying to figure this out for a couple of days, but the end goal is to make a trail shop. Started by using i,v pairs to loop through a folder, and check if its a text button, then making it where you are able to equip and unequip by clicking that text button, and firing a remote event to do all of the trail magic.

the biggest problem in chat gpt is that the scripts never work and it sometimes doesn’t understand what you need. also when i tested a code from it, it used a something that doesn’t exist and said it needed a “business” plan to use it in studio

The code is basically the same. ChatGPT’s version just adds edits the button’s appearance when equipped.