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 script?!?!?!

What is wrong with this script I want to make this Shop Gui work!

player = script.Parent.Parent.Parent.Parent.Parent 
Points = player.leaderstats.Cash
upgradeStuff = game.Lighting.GravityCoil 

function buy()
if Points.Value >= 250 then 

	Points.Value = Points.Value - 250 

        upgradeStuff:clone().Parent = player.Backpack 

	wait(2)
else 
        script.Parent.Parent.Text = "You cant afford this!" 
	wait(3)
        script.Parent.Parent.Text = "Gravity Coil"  
end
end

script.Parent.MouseButton1Down:connect(buy)


Plz help with instructions on what each line does

1 comment

2

plz vote my post up so i can get my reputaion up cuz right now i cant vote for others

1 answer

player = script.Parent.Parent.Parent.Parent.Parent --This creates a variable for the player
Points = player.leaderstats.Cash --This makes a variable for their "Cash" value in leaderstats. If there isn't one, then this would cause an error. Giving us the output improves the likelyhood of us being able to give a good answer. I would replace this line with Points=player:WaitForChild("leaderstats"):WaitForChild("Cash")
upgradeStuff = game.Lighting.GravityCoil --This makes a vairable for the item being bought. Using ReplicatedStorage for storing things is better than Lighting tho.

function buy()--Creates a function to be called when the button's clicked.
if Points.Value >= 250 then --This checks if they have 250 points or more.

    Points.Value = Points.Value - 250 --This subtracts from their points

        upgradeStuff:clone().Parent = player.Backpack --This gives them the gravity coil

    wait(2)--Waits a bit, not quite sure why this is here.
else --If they don't have enough points
        script.Parent.Parent.Text = "You cant afford this!" --Tell them they can't afford it
    wait(3)--Wait a bit
        script.Parent.Parent.Text = "Gravity Coil"  --Return the text to normal
end--Idk how to explain "end" to you. Check wiki.roblox.com for that one.
end

script.Parent.MouseButton1Down:connect(buy())--Don't forget the arguments for the buy function, even if they're empty.

4 comments

1

k thanks and yes i know what end means... lol

0

lol, well you asked for instructions on what each line does :P Np

1

umm why is replicated storage better?

0

The wiki said so.

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