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

Help! My code/Shop gui wont work in the real game!? What is the problem!?

This is my code

`player = script.Parent.Parent.Parent.Parent.Parent

local tool = game.ServerStorage:FindFirstChild("Rossi Extend") -- Make sure to put the tool in ServerStorage!

Balance = 10 -- Set here how much money you want for this item to cost!

money = player.leaderstats.Cash

-- This script uses TextButton, or ImageButton1 script.Parent.MouseButton1Click:connect(function() if money.Value >= Balance then

local item = tool:Clone() item.Parent = player.Backpack

money.Value = money.Value - Balance -- Remove this line if you want that you don't lose your money when you purchase this item! Otherwise, leave this! end end)`

4 comments

0

Come back when you write your own code.

0

wat?

0

Sigh It's very clear you didn't write this code...

0

LOL! -27 reputation. Try to learn roblox lua before going for help in forums.

1 answer

✓ Accepted answer

There’s lots wrong with that free model code.

I. The writer set the player variable to like 50 script.Parent’s. Why? Since this a LocalScript, just use LocalPlayer.

II. The writer used ServerStorage on the client. It doesn’t exist in the client, only the server. Instead edit it to use ReplicatedStorage, where both client and server can access it.

III. In the MouseButton1Click event, it uses deprecated :connect when it’s :Connect.

local player = game:GetService("Players").LocalPlayer
local rep = game:GetService"ReplicatedStorage"
local tool = rep:FindFirstChild"Rossi Extend"
local amt = 10
local money = player.leaderstats.Cash

script.Parent.MouseButton1Click:Connect(function()
    if money.Value >= amt then
        tool:Clone().Parent = player.Backpack
        money.Value = money.Value - amt
    end
end)

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