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…
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).
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.
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…
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.