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

Could someone please fix this script?

I've tried absolutely everything, but nobody can seem to help me.

plr = game
price = 0
brick = script.Parent.Parent.Parent["Seasoner - 1200"].Head

 script.Parent.Touched:connect (function() 
	local v = plr.leaderstats.Cash
	if  v.Value - price == 0 then 
		brick.Transparency = 0
	else brick.Transparency = 1
	end
end)

What I am trying to do, is make it so that when you have enough money, and step on a brick, another brick (that already exists) will appear.

This is a regular (not local) script in models in workspace

if there is a different way to do this, please tell me.

1 comment

0

First of all, you need to do more than this. Second of all, 'plr' is set to game, not a player. Third, you need to receive the player when the part is touched. And finally, it would help us if you gave us what the error in the output is.

1 answer

✓ Accepted answer
local price = 0
local brick = script.Parent.Parent.Parent:WaitForChild("Seasoner - 1200"):WaitForChild("Head")

brick.Transparency = 1

function doPurchase(cash) -- Just makes it easier to read.
	if cash.Value >= price then
		cash.Value = cash.Value - price
		brick.Transparency = 0
	else
		print("Not enough cash")
	end
end

script.Parent.Touched:connect(function(hit)
	local player = game.Players:playerFromCharacter(hit.Parent)

	if player then
		local stats = player:findFirstChild("leaderstats")

		if stats then
			local cash = stats:findFirstChild("Cash")

			if cash then
				doPurchase(cash)
			end
		end
	end
end)

1 comment

0

Thank you so much if you ever need/want it, I have 30 robux to give.

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