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

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

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

3 comments

0

u gotta do currency exchanges from the server, learn remotevents or attempt to turn off filtering enabled

0

u gotta do currency exchanges from the server, learn remotevents or attempt to turn off filtering enabled

0

dont create new memory object .. instead just assign instance cost = script.Parent.Cost and then add to your code cost.Value

3 answers

✓ Accepted answer

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

2 comments

1

Let God have you in care :D

1

<3 :D

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

4 comments

0

But don't work idk why the Cost.Value didn't change still :(

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.

0

STILL NOT CHANGE VALUE OF Cost IDK WHY O.O

0

Y'all did him dirty... cost is a number value, not an object..

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)

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