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

Help me on this script?

I am making a town/city game, and I am currently working on the neighborhood, and I am not a good scripter. I built a house but I have a script that tells you how much money you have. But when you buy the house you spend some money. You start off automatically with 1000 dollars. But each house will cost 300 dollars. Here is the script I have so far but I don't think it is correct please help me

function moneyvalue(player)
	local stats = Instance.new("IntValue")
	stats.Name = "Leaderstats"
	local c = Instance.new("IntValue")
	c.name = "Money"
	c.value = 300
	c.parent = stats
	stats.parent = player
	newPlayer.Change:connect (function (property)
		end)
	end
	
	game.Players.ChildAdded:connect (Playerboughthouse)

Thank you, Tristen126

2 answers

✓ Accepted answer

After reading this I'm assuming that you want players to spawn with 1000 dollars and want to be able to deduct money. I can't really help with the buying of house part but I can help with the deducting.

function moneyvalue(player) -- Cleaned up this code alittle
	local stats = Instance.new("IntValue",player)
	stats.Name = "leaderstats"
	local c = Instance.new("IntValue",stats)
	c.Name = "Money"
	c.Value = 1000 -- Starter amount of money
end

function deductmoney(player,amount)
	if player and amount then -- Make sure you passed a player and the amount
		plr = game:GetService("Players"):FindFirstChild(player) -- Get the player
		if plr and plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Money") then -- Make sure they have stats and they are here
			if plr.leaderstats.Money.Value >= amount then
				plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - amount
				return true
			else
				return false
			end
		end
	end
end

game.Players.ChildAdded:connect(moneyvalue)

To remove money from a player all you have to do its run the deductmoney function with the player name and how much to remove. Example :

deductmoney("samfun123",300)

The function will also return true if it deducted money, if the player doesn't have enough money it will returns false.

If you have any questions, concerns or just need some help with this PM me on ROBLOX!

Test it out first, then return a reply with what errors are there.

1 comment

0

I tested it, it worked I am just now confused how to use it e.o

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