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

Sell for tycoon not working and I got no errors... What have I done wrong?

So I just have 3 different things in my leaderstats called oil, what im trying to sell, money what oil needs to become and companyvalue but that has nothing to do with it.

here is the script of my seller: ~~~~~~~~~~~~~~~~~ local multiplier = 1 local db = false

script.Parent.Touched:Connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then if not db then db = true

		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		
		plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + (plr.leaderstats.Oil.Value * multiplier)
		plr.leaderstats.Oil.Value = 0
		wait(1)
		db = false
	end
end

end)


and here is the script of my leaderstats:~~~~~~~~~~~~~~~~~
local DSS = game:GetService("DataStoreService")

local localDataStore = DSS:GetDataStore("localDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new ("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local Money = Instance.new("IntValue", leaderstats)
	Money.Name = "Money"
	
	local CompanyValue = Instance.new("IntValue", leaderstats)
	CompanyValue.Name = "CompanyValue"
	
	local Oil = Instance.new("IntValue", leaderstats)
	Oil.Name = "Oil"
	

I don't know what's wrong please help me! Thanks!

1 comment

0

sorry for the wierd boxes idk what I've done wrong!

1 answer

✓ Accepted answer
game.Players.PlayerAdded:Connect(function(player) -- Get players added and create new folders below
	local leaderstats = Instance.new ("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player -- Avoid doing Instance.new(Type,Parent) as that was depreciated a while ago. It also saves resources to create something, edit all of its values, and then parent it to something.

	local Money = Instance.new("IntValue")
	Money.Name = "Money"
	Money.Parent = leaderstats

	local CompanyValue = Instance.new("IntValue")
	CompanyValue.Name = "CompanyValue"
	CompanyValue.Parent = leaderstats

	local Oil = Instance.new("IntValue")
	Oil.Name = "Oil"
	Oil.Value = 100
	Oil.Parent = leaderstats

end)
local db = false
local multiplier = 1
script.Parent.Touched:Connect(function(hit) -- Detect if part was touched
	if game.Players:FindFirstChild(hit.Parent.Name) and db == false then -- If touched part was a player, and db is false
		db = true
		local player = game.Players:FindFirstChild(hit.Parent.Name) -- Get player
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + (player.leaderstats.Oil.Value * multiplier) -- Add money
		player.leaderstats.Oil.Value = 0 -- Remove oil
		wait(1)
		db = false
	end
end)

Future reference, all code goes inside the ~~~~'s. No text can be on the same line as them either, or you will wind up with messed up boxes like on your post.

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