You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want my buy button to work
What is the issue? Even tho i have enough currency, the tool is not getting bought
What solutions have you tried so far? I have learnt more about remote functions, yet it doesn’t work. I also looked up multiple videos
--Server Side
local remotecon = {}
local items = game.ReplicatedStorage.Shared:WaitForChild("Tools")
function remotecon.buy(player,toolName)
local tool = items:FindFirstChild(toolName)
if tool ~= nil then
if not player.Ownedtools:FindFirstChild(toolName) and player.Equipped.Value ~= toolName then
price = tool.Cost.Value
--plr dosent have tool
if player.leaderstats.Coins.Value >= price then
local newtoolval = Instance.new("StringValue")
newtoolval.Name = toolName
newtoolval.Parent = player
player.Current = toolName
for i,v in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
local gear = tool:Clone()
gear.Parent = player.Backpack
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - price
return "Yes"
else
return "no"
end
elseif player.Ownedtools:FindFirstChild(toolName) and player.Equipped.Value ~= toolName then
for i,v in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
local gear = tool:Clone()
gear.Parent = player.Backpack
return "Equipped"
elseif player.Ownedtools:FindFirstChild(toolName) and player.Equipped.Value == toolName then
for i,v in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
local gear = tool:Clone()
gear.Parent = player.Backpack
return "Equipped"
end
else
return "error"
end
end
game.ReplicatedStorage.Remotes.buytool.OnServerInvoke = function(player,toolName)
remotecon.buy(player,toolName)
end
return remotecon
--Client side
local shop = script.Parent.tools_gui.tools_frame
for i, item in ipairs(Tools) do
if item:IsA("Tool") then
local price = item:FindFirstChild("Cost")
local img = item:FindFirstChild("ImgID")
local order = item:FindFirstChild("order")
if price and img and order then
print(item.Name)
local temp = temp:Clone()
temp.Parent = scrollingFrame
temp.Name = item.Name
temp.img.Image = img.Value
local priceval = Instance.new("StringValue")
priceval.Value = price.Value
priceval.Parent = temp
temp.Visible = true
temp.MouseButton1Click:Connect(function()
shop.tool_img.Image = img.Value
selectedtemp = temp
shop.price.Text = price.Value
shop.name.Text = item.Name
end)
else
continue
end
end
end
if selectedtemp ~= nil then
end
shop.canbuy.MouseButton1Click:Connect(function()
if selectedtemp ~= nil then
local result = game.ReplicatedStorage.Remotes.buytool:InvokeServer(selectedtemp.Name)
end
end)
Also it doesn’t show me any errors. Help is appreciated.Thank you!
--Server Side
local remotecon = {}
local items = game.ReplicatedStorage.Shared:WaitForChild("Tools")
function remotecon.buy(player,toolName)
local tool = items:FindFirstChild(toolName)
if tool ~= nil then
if not player.Ownedtools:FindFirstChild(toolName) and player.Equipped.Value ~= toolName then
price = tool.Cost.Value
--plr dosent have tool
if player.leaderstats.Coins.Value >= price then
local newtoolval = Instance.new("StringValue")
newtoolval.Name = toolName
newtoolval.Parent = player
player.Current = toolName
for i,v in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
local gear = tool:Clone()
gear.Parent = player.Backpack
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - price
return "Yes"
else
return "no"
end
if player.Ownedtools:FindFirstChild(toolName) and player.Equipped.Value ~= toolName then
for i,v in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
local gear = tool:Clone()
gear.Parent = player.Backpack
return "Equipped"
elseif player.Ownedtools:FindFirstChild(toolName) and player.Equipped.Value == toolName then
for i,v in pairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
local gear = tool:Clone()
gear.Parent = player.Backpack
return "Equipped"
end
else
return "error"
end
end
game.ReplicatedStorage.Remotes.buytool.OnServerInvoke = function(player,toolName)
remotecon.buy(player,toolName)
end
return remotecon
im not trying to do a one-way communication if so then remote event is the option. But i am trying to do two-way communication so im using remote functions.
So everything rpints but the client side aint printing, only in this function:
shop.canbuy.MouseButton1Click:Connect(function()
if selectedtemp ~= nil then
local result = game.ReplicatedStorage.Remotes.buytool:InvokeServer(selectedtemp.Name)
print("buying")
end
end)
shop.canbuy.MouseButton1Click:Connect(function()
if selectedtemp ~= nil then
local result = game.ReplicatedStorage.Remotes.buytool:InvokeServer(selectedtemp.Name)
print("buying")
end
end)
Also in this script you gotta spam print statements too. What I’d do is literally do a print() at every line. Could be very tedious but it solved 99% of my problems