Tool not equipping upon button press

Hi everyone, I have an issue with a tool equipping system I made, but the output doesn’t output anything… The item can be first purchased for 50 points (that works fine), and then equipped (that doesn’t work)… I tried debugging it with print statements although that did not work, and nothing printed in the output. Even though all the if/else conditions are checked, the program doesn’t do what is asked. Here is the code and a video showing you the issue.

local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage");
local player = game:GetService("Players").LocalPlayer;
local backpack = player:WaitForChild("Backpack");

local tool1 = "LoveSign";
local toolClone;
local button = script.Parent
local frame = script.Parent.Parent

local ItemName = frame.ItemName
local ItemDescription = frame.ItemDescription
local ItemPurchaseButton = frame["Purchase/EquipItem"]
local ItemImage = frame.ItemImageFrame.ImageLabel


script.Parent.MouseButton1Click:Connect(function()
	if ItemName.Text == "Love sign" and plr.ItemsOwned.LoveSignOwned.Value == false and plr.leaderstats.Points.Value >= 50 then
		plr.ItemsOwned.LoveSignOwned.Value = true
		ItemPurchaseButton.Text = "Equip"
		plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - 50
	elseif ItemName == "Love sign" and plr.ItemsOwned.LoveSignOwned.Value == true then
		print("Item owned and clicked")
		if not toolClone then
			print("not ToolClone()")
			toolClone = replicatedStorage[tool1]:Clone()
			toolClone.Parent = backpack
			button.Text = "Unequip"
		end
	elseif ItemName == "Love sign" and ItemPurchaseButton.Text == "Unequip" then
		print("Item unequipped")
		toolClone.Parent = nil;
		toolClone = nil;
		button.Text = "Equip"
	end
end)

In the end of the video I am clicking the “equip” button, it just isn’t working…

Can you show me the folder where you keep the tools?

Also why are you making local toolclone;

Why are there two equip buttons? One is in the store GUI and the other is on the right side of the screen.

The tools are located in ReplicatedStorage. Also the clone was used from another script that went like this:

local replicatedStorage = game:GetService("ReplicatedStorage");
local player = game:GetService("Players").LocalPlayer;
local backpack = player:WaitForChild("Backpack");

local button = script.Parent;
local toolName = "x2SpeedItem";
local toolClone;

button.MouseButton1Click:Connect(function(plr)
	--check if the tool exist
	if not toolClone then
		--if the tool doesn't exist already, give the player the tool
		toolClone = replicatedStorage[toolName]:Clone();
		toolClone.Parent = backpack
		
		button.Text = "Unequip"
	else
		--if the tool doesn't exist, then we should remove the tool, effectively setting toolClone to nil
		toolClone.Parent = nil;
		toolClone = nil;
		button.Text = "Equip"
	end
end)

Right… You should ignore the white button, it was a test for another tool, which is where i got the script for the new one as well btw (see my response to @Haukly’s post).

Why not just do:
toolClone = replicatedStorage:FindFirstChild(“LoveSign”):Clone()

So later on, this one button will handle equipping different tools, so clone has to be different things (that is determined in previous scripts)

Edit: I just Tested this and it didn’t seem to work…

Alright. You know how you said that when you tried using print statements to debug it wouldn’t print? What line did the print last get to. Because, it should not just, not appear.

So none of the prints printed… absolutely NONE of them!!!

Not even the one when you’re purchasing the item?
Also, you forgot to add .Text here:

elseif ItemName.Text == "Love

Let me know if that helped

Oh yes, that one did print, I just didn’t have it at first because it was working.

What about the elseif’s ItemName.Text. When you fixed that did it work?

what do you mean? How does that need to be fixed?

You’re just calling the ItemName. Not the ItemName’s Text.

1 Like

Thank you. Easy fix which i didnt notice! Now I have another problem, which is that the item will not unequip since the both the requirements for equip and unequip are met in the function…

Edit: Nevermind I got it!

No worries! It happens to all of us.
Just to make sure, did you also edit the second elseif’s ItemName.Text ?

1 Like

Yes, I did… (30 friggin characters)

Okay, so according to that. When you now buy it, are you able to equip it?

Is this fixed, if it is please select which ever asnwer was the solution.

You shouldn’t be handling this entire workflow from a LocalScript. You need to get accustomed towards having your systems function with the client-server model in mind not only for security purposes but also for understanding how to construct systems appropriately.

When it comes to a Shop Gui, the client should only be responsible as much as handling the Gui, so tabs and the state of the tool being equipped. Ideally you should also make this arbitrary because a lot of what you have is hard coded and will just become more painful when you go out to make more tools for sale.

The client should only request, as far as purchasing goes, to the server via a RemoteEvent to conduct a purchase and grant users tools, as well as track what they own so they don’t attempt to equip tools they haven’t bought. Clients can easily spoof their cash value and purchase anything they want, so never handle that kind of critical task from the client.

Alright, I guess that is very smart, but I never quite understood how I can get the LocalPlayer in a regular script, since I would need to use that to make it Server Side.