Tool not equipping upon button press

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.

You don’t get the LocalPlayer in a server script, you get it from the first argument of a RemoteEvent. This whole system doesn’t need to be server-side: only the buying bit, tracking inventory (for security) and granting tools and that should all be central within ServerScriptService.

2 Likes