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

My buy script isn't functioning fully, is there something wrong?

Here's my script. When the player Prestige, I also wanted to give them a certain amount of stat on Prestige (in leaderstats), but this don't seem to work, what am I doing wrong?

local items = script.Parent.Frame:GetChildren()
for i = 1, #items do
function buy()
local Cash = script.Parent.Parent.Parent.Parent.leaderstats:FindFirstChild(items[i].Currency.Value)
local Prestige = script.Parent.Parent.Parent.Parent.leaderstats:FindFirstChild(items[i].Prestige.Value)
if Cash.Value >= items[i].Cost.Value then
Cash.Value = Cash.Value - items[i].Cost.Value
Prestige.Value = Prestige.Value + items[i].Prestige.Value
local toolca = game.Lighting:FindFirstChild(items[i].ItemName.Value):Clone()
local toolcb = game.Lighting:FindFirstChild(items[i].ItemName.Value):Clone()
toolca.Parent = script.Parent.Parent.Parent.Parent.Backpack
toolcb.Parent = script.Parent.Parent.Parent.Parent.StarterGear
end
end
items[i].BuyButton.MouseButton1Click:connect(buy)

end

2 comments

0

Please be more specific as what you want the script to do, because i made a buy script once and it was different than this and this i dont understand, ex : when you click a gui it takes away cash from leaderstats, when clicking a brick...

0

no, when you touch a brick the GUI comes up, and when you click the buy button it takes the money from the leaderstat. It works fine for the item giving part, but it just doesn't +1 to the Prestige stat on the leaderboard.

1 answer

(In a LocalScript) I cleaned up the script, so yeah.

NOTE: This is not tested.

local items = script.Parent.Frame:GetChildren()
local plr = game.Players.LocalPlayers

while wait(0.01) do
	for i = 1, #items do
		items[i].BuyButton.MouseButton1Click:connect(function()
			local Cash = plr.leaderstats:FindFirstChild(items[i].Currency)
			local Prestige = plr.leaderstats:FindFirstChild(items[i].Prestige)
			if Cash.Value >= items[i].Cost.Value then
				Cash.Value = Cash.Value - items[i].Cost.Value
				Prestige.Value = Prestige.Value + 1 -- You might had've forgotten this
				local toolca = game.Lighting:FindFirstChild(items[i].ItemName.Value):Clone()
				local toolcb = game.Lighting:FindFirstChild(items[i].ItemName.Value):Clone()
				toolca.Parent = plr.Backpack
				toolcb.Parent = plr.Backpack
			end
		end)
	end
end

Hope this helped!

1 comment

0

nope didn't work..

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