Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My script seems to be off about the Shop i made, Can anyone help me with it?

Asked by 7 years ago

By script was supposed to give you a sniper and takes away $100 then once you have it and its you're backpack you can't get another one. But the only thing that works is when it takes away the money.

Script:

local Cash = game.Players.LocalPlayer.leaderstats.Cash -- change Cash to your currency
function onClicked()
if Cash.Value >= 100 then --change 350000 to the amount it costs
Cash.Value = Cash.Value - 100 --change 350000 to the amount it costs
end
end

script.Parent.MouseButton1Down:connect(onClicked)

local price = script.Parent.Parent.BuyNowSniper
local Player = script.Parent.Parent.Parent.Parent.Players.LocalPlayer

Tool = script.Parent

Tool.Equipped:connect(function()
if game.Players[Tool.Parent.Sniper].Backpack:FindFirstChild(Tool.Sniper) ~= nil then
price.Text = "You Already Have That Item"
end
end)

local p = game.Players.LocalPlayer
local Cash = game.Players.LocalPlayer.leaderstats.Cash

script.Parent.MouseButton1Click:connect(function()
        local tool = script.Parent.Sniper:Clone()
    tool.Parent = p.Backpack
end)

what do i need remove or add? Thanks, Peace :3

1 answer

Log in to vote
0
Answered by
Viking359 161
7 years ago

Next time, dont use a free model. Also, make sure this is in a local script if you are using local player.

local player = game.Players.LocalPlayer
local Cash = player.leaderstats.Cash
local price = 100
local backpack = player.Backpack
local text = "Whatever the textbutton says right now"
script.Parent.MouseButton1Down:Connect(function(onClicked)
if Cash.Value >= price and backpack:FindFirstChild("Sniper") == nil then
Cash.Value = Cash.Value - price
local tool = script.Parent.Sniper:Clone()
tool.Parent = backpack
local Tool = tool:Clone()
tool.Parent = player.StarterPack
elseif backpack:FindFirstChild("Sniper") then
    script.Parent.Text = "You already have that!"
    wait(1)
    script.Parent.Text = text
elseif Cash.Value < price then
    script.Parent.Text = "You can't afford that!"
    wait(1)
    script.parent.Text = text
else
    script.Parent.Text = "There was an error purchasing this!"
    wait(1)
    script.Parent.Text = text
end
end)

I'm assuming the sniper is a child of the text button, along with the script.

Ad

Answer this question