so im making a simulator and im trying to sell a currency called “MnMs” (m&m simulator) and im trying to make a script where if i touch a part it will sell the currency and give me money which is called “Mcash”
the Sell script.
local Part = script.Parent
local id = 17679492
Part.Touched:Connect(function(hit)
local H = hit.Parent:FindFirstChild("Humanoid")
if H then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local leaderstats = player:WaitForChild("leaderstats")
local Currency = leaderstats.Mcash -- change cash to your stat name
local Selling = leaderstats.MnMs -- change apples to your stat name
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value * 4
Selling.Value = 0
end
else
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value * 2
Selling.Value = 0
end
end
end
end
end)
the leaderboard script:
local player = game:GetService("Players")
local function leaderboardsetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local mms = Instance.new("IntValue")
mms.Name = "MnMs"
mms.Value = 0
mms.Parent = leaderstats
local money = Instance.new("IntValue")
money.Name = "Mcash"
money.Value = 0
money.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(leaderboardsetup)
What is the actual problem with the script? Any errors in output? Also I think you have to do local Currency = leaderstats:WaitForChild("Mcash") instead of just using . to define it.
local Part = script.Parent
local id = 17679492
Part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local leaderstats = player.leaderstats
local Currency = leaderstats.Mcash -- change cash to your stat name
local Selling = leaderstats.MnMs -- change apples to your stat name
if Selling.Value <= 0 then return end
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
Currency.Value += Selling.Value * 2
else
Currency.Value += Selling.Value
end
Selling.Value = 0
end
end)
local Part = script.Parent
local id = 17679492
Part.Touched:Connect(function(hit)
local H = hit.Parent:FindFirstChild("Humanoid")
if H then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local leaderstats = player:WaitForChild("leaderstats")
local Currency = leaderstats:WaitForChild("Mcash")-- change cash to your stat name
local Selling = lleaderstats:WaitForChild("MnMs")-- change apples to your stat name
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value * 4
Selling.Value = 0
end
else
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value * 2
Selling.Value = 0
end
end
end
end
end)
The only thing that doesn’t work is the gamepass part. I might try fixing that later.
-- When a player touches the parent object, their items will be sold for gold
local sellPart = script.Parent
-- Gives the player gold for each item they have
local function sellItems(playerItems, playerGold)
-- Gives players 10 pieces of gold for each item
local totalSell = (playerItems.Value * 10)
playerGold.Value = playerGold.Value + totalSell
playerItems.Value = 0
end
local function onTouch(partTouched)
-- Looks for a Humanoid
local character = partTouched.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
-- If a humanoid is found, gets leaderstats and calls sellItems function
if humanoid then
-- Get the player, so changes can be made to the player's leaderstats
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
local playerStats = player:FindFirstChild("leaderstats")
local playerItems = playerStats:FindFirstChild("MnMs")
local playerGold = playerStats:FindFirstChild("Mcash")
-- Sells Items and then changes the player's spaces and money
sellItems(playerItems, playerGold)
end
end
sellPart.Touched:Connect(onTouch)