Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is wrong with this?

local player = game.Players.LocalPlayer
local currency = player:WaitForChild('leaderstats').Points
local amount = 5
local tool = game.ServerStorage:WaitForChild('Firebrand')
script.Parent.MouseButton1Click:connect(function()
 if currency.Value >= amount and not player.Backpack:FindFirstChild("Firebrand")or player.Character:FindFirstChild('Firebrand') then
  -- They Dont Have it
  local newtool = tool:Clone()
  newtool.Parent = player.Backpack
 else
  script.Parent.Text = 'Purchase Failed'
 end
end)

2 comments

1

We need to know what is wrong with it in order to answer your question. Do you get errors in output? What does it not do that it's supposed to do?

0

I can test the game but it does not do anything

1 answer

ServerStorage is exactly that -- storage for the server -- not the client. LocalScripts do not have access to anything in ServerStorage -- ROBLOX won't bother sending them those files.

If you want to make a model available to clients (i.e., LocalScripts) you have to use ReplicatedStorage.


Also, your order-of-operations is wrong with or, and, and not.

if a and not b or c is interpreted as if (a and (not b)) or c then. Thus the purchase will go through if they have it in their character, even if they don't have enough money.

This discussion is preserved as it was. New answers, comments, and votes are closed.