Need help with sell system (basic)

so i have my leaderstats, and that works. but i’m trying to make it so that when the player steps on the part, they lose their “hotdogs” value, and the amount of hotdogs they had, goes adds to the cash amount. so basically a simulator sell system.

here is my code:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local Hotdogs = Instance.new("IntValue",leaderstats)
	Hotdogs.Name = "Hotdogs"
	
	local Cash = Instance.new("IntValue",leaderstats)
	Cash.Name = "Cash"
end)


local sell = game.Workspace.Part
local currentval = game.Players.LocalPlayer.leaderstats.Hotdogs.Value

sell.Touched:connect(function(hit)
	local player = game.Players.LocalPlayer
	if game.Players:GetPlayerFromCharacter(hit.Parent)then
		player.leaderstats.Hotdogs.Value = player.leaderstats.Hotdogs.Value - player.leaderstats.Value
		player.leaderstats.Cash.Value = player.leaderstats.Value + currentval
	end
end)

thanks

Are there any issues? Such as errors in the output or is it just not working?

Think yuo’d do something like this for the touched event

local sell = game.Workspace.Part

sell.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if not player then return end
	local stats = player.leaderstats
	local dogs = stats.Hotdogs
	local cash = stats.Cash
	
	cash.Value += dogs.Value
	dogs.Value = 0
end)

Get the player and get the stats, add to the cash the amount of hotdogs you have and set the hotdogs to 0

Must be a server script, which shouldn’t be an issue if this is with your leaderstats code

2 Likes

Bro Try To Do

local sell = game.Workspace.Part

sell.Touched:Connect(function(hit)
local player = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent)
if not player then return end
local stats = player.leaderstats
local dogs = stats.Hotdogs
local cash = stats.Cash

cash.Value =  cash.Value + dogs.Value * 1 -- change the 1 to your multi
dogs.Value = 0

end)

1 Like