Sunday, May 5, 2013

ROBLOX Scripting: A Buy Button

I've been on ROBLOX for a fair time now, and I've advanced myself to high scripting knowledge, but when I first started learning to script, this was a hard job. So, I'm going to make it easy for you..

When you're making a shop in a gui, you'll wanna know how much of their leaderstats that player has. And if they have that many then it will take it away, this can be performed with a simple "if" statement. Like so:

My leaderstats name is cash, and my button is in a screengui which is in startergui..

if script.Parent.Parent.Parent.Parent.leaderstats.cash.Value>=20 then
game.Lighting.Item:clone().Parent=script.Parent.Parent.Parent.Parent.Backpack
game.Lighting.Item:clone().Parent=script.Parent.Parent.Parent.Parent.StarterGear
script.Parent.Parent.Parent.Parent.leaderstats.cash.Value=script.Parent.Parent.Parent.Parent.leaderstats.cash.Value - 20
else
print("Can't be bought "..script.Parent.Parent.Parent.Parent.Name.." doesn't have enough.")
end
end
script.Parent.MouseButton1Click:connect(click)

This would take away 20 cash if the player has 20 or more cash, it would also print that the player doesn't have enough cash if they can't buy it.
To see a full understanding of if statements click here.

Thanks for reading this short, and easy post..

~Zakary99

Questions?
Pm me on ROBLOX
or
Tweet me on twitter @RBX_Zakary99