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

I wanna make script to change value of 'cost' to 0 :P Can You help me ? SOLVED

Asked by
ErtyPL 129
6 years ago
Edited 4 years ago
player = script.Parent.Parent.Parent.Parent.Parent.Parent
gold = player.leaderstats.Cash
cost = script.Parent.Cost.Value
getItem = game.Lighting.ErtYhop.Listed.ChezBurger
    function buy()
        if gold.Value >= cost then
    gold.Value = gold.Value - cost
    local a = getItem:clone()
    a.Parent = player.Backpack
    cost = 0 -- idk here 
    wait(1)
    end
script.Parent.ImageTransparency = 0.9
script.Parent.ImageColor3 = 21, 158, 165 
wait(1)
script.Parent.ImageTransparency = 0.3
end
script.Parent.MouseButton1Down:connect(buy

) Hey Ho ! I wanna make this script to change value of 'cost' to 0 cost = 0 - idk here

Can You help me ? I'm new to lua :P

0
u gotta do currency exchanges from the server, learn remotevents or attempt to turn off filtering enabled greatneil80 2647 — 4y
0
u gotta do currency exchanges from the server, learn remotevents or attempt to turn off filtering enabled greatneil80 2647 — 4y
0
dont create new memory object .. instead just assign instance cost = script.Parent.Cost and then add to your code cost.Value PROREMIXPL 60 — 2y

3 answers

Log in to vote
1
Answered by
thesit123 509 Moderation Voter
6 years ago

Make sure the parent of the script is TextButton and the script is LocalScript not normal script, nor ModuleScript.

script.Parent.MouseButton1Click:connect(function(buy)
    local Plr = game.Players.LocalPlayer
    local gold = Plr.leaderstats.Cash
    local cost = script.Parent.Cost
    local getItem = game.Lighting.Tool -- Your Tool Location

    if gold.Value >= cost.Value then 
        gold.Value = gold.Value - cost.Value
        getItem:Clone().Parent = Plr.Backpack
        cost.Value = 0
        wait(1)
    end

    -- Other Coding
end)

Other then that GOOD2GO

1
Let God have you in care :D ErtyPL 129 — 6y
1
<3 :D thesit123 509 — 6y
Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

When you set script.Parent.Cost.Value to a variable, it only set the current value to that variable. When you set cost = 0, you changed only the value of the variable, not Cost.Value.

To change Cost.Value, you must do it directly

Cost.Value = --whatever value you want

Hopefully this is what you are looking for. If you just wanted to change the variable cost, it's as simple as what you already have

cost = 12345 -- or whatever number you want
0
But don't work idk why the Cost.Value didn't change still :( ErtyPL 129 — 6y
0
For the variable, do "script.Parent.Cost" then everytime you use the variable, do Cost.Value. Just change the Cost value to 0 to answer your question. User#2146 0 — 6y
0
STILL NOT CHANGE VALUE OF Cost IDK WHY O.O ErtyPL 129 — 6y
0
Y'all did him dirty... cost is a number value, not an object.. Bellyrium 310 — 6y
Log in to vote
0
Answered by
Bellyrium 310 Moderation Voter
6 years ago
Edited 6 years ago
player = script.Parent.Parent.Parent.Parent.Parent.Parent
gold = player.leaderstats.Cash
cost = script.Parent.Cost -- change this to just the item
getItem = game.Lighting.ErtYhop.Listed.ChezBurger
    function buy()
        if gold.Value >= cost.Value then -- all places you use cost, now use cost.Value
    gold.Value = gold.Value - cost.Value
    local a = getItem:clone()
    a.Parent = player.Backpack
    cost.Value = 0 -- idk here 
    wait(1)
    end
script.Parent.ImageTransparency = 0.9
script.Parent.ImageColor3 = 21, 158, 165 
wait(1)
script.Parent.ImageTransparency = 0.3
end
script.Parent.MouseButton1Down:connect(buy)

Answer this question