Short line of code, having issues

Can someone help me figure out what I’m doing wrong with this line of code?

When someone clicks on the button, at the same time the TextLabel says “Equipped” then I want the script to change the TextLabel to “Equip” and remove player.Character.Pet

script.Parent.MouseButton1Click:Connect(function()
if script.Parent.TextLabel.Text == “Equipped” then
script.Parent.TextLabel.Text = “Equip”
player.Character.Pet:Destroy()
end
end)

1 Like

You cannot use if script.Parent.text ==
Instead you would need a bool or string value to do this

I’m still having a bit of trouble working that in

er…

That would be incorrect, you actually can use TextLabel.Text == “string”…

Anyhow, @JJ71599 the bug with your code is that you haven’t defined the ‘player’ instance.
local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.TextLabel.Text == “Equipped” then
script.Parent.TextLabel.Text = “Equip”
if Char:FindFirstChild(“Pet”) then
Char.Character.Pet:Destroy()
end
end
end)

Yeah, I’m still new to programming.

I’m still having some issues, here is the entire script.

local player = game.Players.LocalPlayer
local item = script.Parent.Parent.Parent.Item
local shop = game.Workspace.PetShop
local currency = player.leaderstats[player:WaitForChild(“PetShop”).Currency.Value]

script.Parent.MouseButton1Click:Connect(function()
if script.Parent.TextLabel.Text == “Equip” and script.Parent.TextLabel.Text ~= “Equipped” then
script.Parent.TextLabel.Text = “Equipped”
script.Parent.BackgroundColor3 = Color3.new(0.7,0.7,0.7)
game.ReplicatedStorage.EquippedE:FireServer(item.Value)
end
if shop.Parts:FindFirstChild(“Model”…item.Value) then
if currency.Value >= shop.Parts:FindFirstChild(“Model”…item.Value).ItemPrice.Value then
if script.Parent.TextLabel.Text ~= “Equip” and script.Parent.TextLabel.Text ~= “Equipped” then
script.Parent.TextLabel.Text = “Equipped”
script.Parent.BackgroundColor3 = Color3.new(0.7,0.7,0.7)
game.ReplicatedStorage.EquippedE:FireServer(item.Value)
game.ReplicatedStorage.ShopBuyE:FireServer(item.Value)

		end
	end
end

end)

script.Parent.MouseButton1Click:Connect(function()
if script.Parent.TextLabel.Text == “Equipped” then
script.Parent.TextLabel.Text = “Equip”
player.Character.Pet:Destroy()
end
end)

1 Like

Wdym

You can do this. The Text property of a textlabel is a string, your checking if the string is equal to equipped. There is nothing wrong about it.

The biggest issue in your script was your use of double quote marks( " ) and double dot ( … ), it looks like you were using different symbols, but similar.

Example:
You were using when you were supposed to use "
And using when you were supposed to use ..

Actually there’s one more issue, and it’s about the currency.
You put this:
local currency = player.leaderstats[player:WaitForChild(“PetShop”).Currency.Value]

Basically means this:
local currency = player.leaderstats[game.Players.LocalPlayer:WaitForChild(“PetShop”).Currency.Value]
I imagine you don’t have those folders(game.Players.LocalPlayer) inside your leaderstats

Then you could just use:
local currency = player.leaderstats:WaitForChild("PetShop").Currency.Value

Here is your code but written correctly:

local player = game.Players.LocalPlayer
local item = script.Parent.Parent.Parent.Item
local shop = game.Workspace.PetShop
local currency = player.leaderstats.Currency -- Change this to the correct directory

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.TextLabel.Text == "Equip" and script.Parent.TextLabel.Text ~= "Equipped" then
		script.Parent.TextLabel.Text = "Equipped"
		script.Parent.BackgroundColor3 = Color3.new(0.7,0.7,0.7)
		game.ReplicatedStorage.EquippedE:FireServer(item.Value)
	end
	if shop.Parts:FindFirstChild("Model" .. item.Value) then
		if currency.Value >= shop.Parts:FindFirstChild("Model" .. item.Value).ItemPrice.Value then
			if script.Parent.TextLabel.Text ~= "Equip" and script.Parent.TextLabel.Text ~= "Equipped" then
				script.Parent.TextLabel.Text = "Equipped"
				script.Parent.BackgroundColor3 = Color3.new(0.7,0.7,0.7)
				game.ReplicatedStorage.EquippedE:FireServer(item.Value)
				game.ReplicatedStorage.ShopBuyE:FireServer(item.Value)
			end
		end
	end
end)

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.TextLabel.Text == "Equipped" then
		script.Parent.TextLabel.Text = "Equip"
		player.Character.Pet:Destroy()
	end
end)

IMPORTANT: In case you want to keep your game protected, it would be good if the currency check was on a server side script

I hope this works correctly, have a great day!

Edit: I understood now what you were trying to do on line 4, but I just realized that it has a .Value at the end of it, and in the if statement it has a currency.Value, it’s like you’re writing: currency.Value.Value
Put in line 4 where your currency will be, as far as I know, what you put will not return the value you want.

I imagine it looks like this:
local currency = player.leaderstats:WaitForChild("Currency")

Edit2: Maybe you used double quote marks and double dot correctly, but the devforum changed when publishing, the next time you send a code use:
```
Your code here
```

Example:
```
print(“Hello World!”)
```

Result:

print("Hello World!")

Yes you can. Textlabels do have a "text: property, and they are strings.