Hello! How can I make this Script make a sound when you sell? But when you can’t sell anything, it does not make a sound.
Script:
local Part = script.Parent
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.Money
local Selling = leaderstats.Coins
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value *1
Selling.Value = 0
end
end
end
end)
Its really easy to do this you just need a sound you want to play the script would look like this -
local Part = script.Parent
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.Money
local Selling = leaderstats.Coins
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value *1
Selling.Value = 0
local Sound = Instance.new("Sound",HIT.Parent)
Sound.SoundId = "rbxassetid://" -- Whatever the sound id you want to play is goes here
Sound:Play()
game.Debris:AddItem(Sound,1)
end
end
end
end)
local Part = script.Parent
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.Money
local Selling = leaderstats.Coins
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value *1
Selling.Value = 0
local sound = game.lighting.SoundName --add ur sound into lighting and put the name here
sound:Play()
end
end
end
end)
What do you mean? Are you talking about the ID Inside the Audio, cause I already have that. What do you exactly mean. Where are you talking about? (oh wait one second)
local sound = workspace.sound --change sound to name of the sound instance
local Part = script.Parent
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.Money
local Selling = leaderstats.Coins
if Selling.Value > 0 then
sound:Play()
Currency.Value = Currency.Value + Selling.Value *1
Selling.Value = 0
end
end
end
end)
Much simpler way of achieving the same result. I’ve also fixed the formatting.
local Part = script.Parent
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.Money
local Selling = leaderstats.Coins
if Selling.Value > 0 then
Currency.Value = Currency.Value + Selling.Value *1
Selling.Value = 0
local Sound = Instance.new("Sound",HIT.Parent)
Sound.SoundId = "rbxassetid://" -- Whatever the sound id you want to play is goes here
Sound:Play()
game.Debris:AddItem(Sound,1)
end
end
end
end)