Global Sound issue with Zeds tycoon kit

Hey everyone!

I am working on a game using zeds tycoon kit. So now I’m pretty far along and I’ve adjusted a lot, I find out during testing with friends that you hear each other’s sound when you buy something…?
Searched a lot on the internet but couldn’t find a solution. Were you able to solve this problem?

I Think the problem is in the file PurchaseHandler in each tycoon:

	function Sound(part,id)
		if part:FindFirstChild('Sound') then
			return
		else
			local Sound = Instance.new('Sound',part)
			Sound.SoundId = "rbxassetid://"..tostring(id)
			Sound:Play()
			delay(Sound.TimeLength, function()
				Sound:Destroy()
			end)
		end
	end

I Tried: Sound.MaxDistance = 20
Or

RespectFilteringEnabled = true

Nothing seems to work?

Could you please help me :slight_smile:

1 Like

I personally have never used the tycoon kit, but I have a few questions to ask.

  1. Is the sound directional and does it change as you walk away from the source?
    • If there’s a source, then the issue is most likely that the volume is too high
  2. Is this in a local or global script?
    • If it is global, then it is most likely that the volume is too high
    • If it is local, then it could be that the function gets triggered for ALL clients instead of just one

If it is a global issue, then your Sound.MaxDistance = 20 solution should work. Make sure you add it before you play the sound but after you have initialized the sound:

Code Sample
function Sound(part,id)
		if part:FindFirstChild('Sound') then
			return
		else
			local Sound = Instance.new('Sound',part)
			Sound.SoundId = "rbxassetid://"..tostring(id)
            Sound.MaxDistance = 20
			Sound:Play()
			delay(Sound.TimeLength, function()
				Sound:Destroy()
			end)
		end
	end

If you are unsure if it is the sound handler, try to debug it by either using the Roblox debugger or by using print statements. Here is how you would use a print statement to debug:

Code Sample
function Sound(part,id)
        print("Sound Function Invoked")
		if part:FindFirstChild('Sound') then
			return
		else
            print("Sound Creation")
			local Sound = Instance.new('Sound',part)
			Sound.SoundId = "rbxassetid://"..tostring(id)
            Sound.MaxDistance = 20
			Sound:Play()
			delay(Sound.TimeLength, function()
				Sound:Destroy()
			end)
		end
	end

If you debug, make sure to see if whenever you hear the sound, the lines above are printed. If they aren’t, then the source of the problem comes from somewhere else.

1 Like

Hi thanks for the quick response!
I copied your piece of code with the print in it. But he doesn’t indicate that anywhere. And the code is not in a local script but just in normal script?
Maybe you can open the tycoon yourself so you know what the code looks like?

Also I tried volume to 0.2 But that doesnt work as well:

function Sound(part,id)
	print("Sound Function Invoked")
	if part:FindFirstChild('Sound') then
		return
	else
		print("Sound Creation")
		local Sound = Instance.new('Sound',part)
		Sound.SoundId = "rbxassetid://"..tostring(id)
		Sound.Volume = 0.2
		Sound.MaxDistance = 20
		Sound:Play()
		delay(Sound.TimeLength, function()
			Sound:Destroy()
		end)
	end
end

EDIT: Even Volume = 0 doesnt work sooo…

Here is the complete file of PurchaseHandler(What I think is the problem for the sound)

	--[[
		All configurations are located in the "Settings" Module script.
		Please don't edit this script unless you know what you're doing.
	--]]
	local Objects = {}
	local TeamColor = script.Parent.TeamColor.Value
	local Settings = require(script.Parent.Parent.Parent.Settings)
	local Money = script.Parent.CurrencyToCollect
	local Debris = game:GetService('Debris')
	local Stealing = Settings.StealSettings
	local CanSteal = true -- don't change or else you won't be able to steal currency
	
	script.Parent.Essentials.Spawn.TeamColor = TeamColor
	script.Parent.Essentials.Spawn.BrickColor = TeamColor
	
function Sound(part,id)
	print("Sound Function Invoked")
	if part:FindFirstChild('Sound') then
		return
	else
		print("Sound Creation")
		local Sound = Instance.new('Sound',part)
		Sound.SoundId = "rbxassetid://"..tostring(id)
		Sound.Volume = 0.2
		Sound.MaxDistance = 20
		Sound:Play()
		delay(Sound.TimeLength, function()
			Sound:Destroy()
		end)
	end
end
	
	--Parts that fall into the collector(s) get processed
	for i,v in pairs(script.Parent.Essentials:GetChildren()) do
		if v.Name == "PartCollector" then
			v.Touched:connect(function(Part)
				if Part:FindFirstChild('Cash') then
					Money.Value = Money.Value + Part.Cash.Value
					Debris:AddItem(Part,0.1)
				end
			end)
		end
	end
	
	--Player Touched Collector processor
	deb = false
	script.Parent.Essentials.Giver.Touched:connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player ~= nil then
			if script.Parent.Owner.Value == player then
				if hit.Parent:FindFirstChild("Humanoid") then
					if hit.Parent.Humanoid.Health > 0 then
						if deb == false then
							deb = true
							script.Parent.Essentials.Giver.BrickColor = BrickColor.new("Bright red")
							local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if Stats ~= nil then 
							Sound(script.Parent.Essentials, Settings.Sounds.Collect)
							Stats.Value = Stats.Value + Money.Value
							Money.Value = 0
							wait(1)
							script.Parent.Essentials.Giver.BrickColor = BrickColor.new("Sea green")
							deb = false
							end
						end
					end
				end
			elseif Stealing.Stealing then -- if player isn't owner and stealing is on
				if CanSteal == true then
					CanSteal = false
					delay(Stealing.PlayerProtection, function()
						CanSteal = true
					end)
					if hit.Parent:FindFirstChild("Humanoid") then
						if hit.Parent.Humanoid.Health > 0 then
							local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if Stats ~= nil then
								local Difference = math.floor(Money.Value * Stealing.StealPrecent)
								Sound(script.Parent.Essentials, Settings.Sounds.Collect)
								Stats.Value = Stats.Value + Difference
								Money.Value = Money.Value - Difference
							end
						end
					end
				else
					Sound(script.Parent.Essentials, Settings.Sounds.Error)
				end
			end
		end
	end)
	
	script.Parent:WaitForChild("Buttons")
	for i,v in pairs(script.Parent.Buttons:GetChildren()) do
		spawn(function()
		if v:FindFirstChild("Head") then
			
			local ThingMade = script.Parent.Purchases:WaitForChild(v.Object.Value)
			if ThingMade ~= nil then
				Objects[ThingMade.Name] = ThingMade:Clone()
				ThingMade:Destroy()
			else
				--//Button doesn't have object, remove it
				error('Object missing for button: '..v.Name..', button has been removed')
				v.Head.CanCollide = false
				v.Head.Transparency = 1
			end
									
			if v:FindFirstChild("Dependency") then --// if button needs something unlocked before it pops up
				v.Head.CanCollide = false
				v.Head.Transparency = 1
				coroutine.resume(coroutine.create(function()
					if script.Parent.PurchasedObjects:WaitForChild(v.Dependency.Value) then
						if Settings['ButtonsFadeIn'] then
							for i=1,20 do
								wait(Settings['FadeInTime']/20)
								v.Head.Transparency = v.Head.Transparency - 0.05
							end
						end
						v.Head.CanCollide = true
						v.Head.Transparency = 0
					end
				end))
			end
			
			v.Head.Touched:connect(function(hit)
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if v.Head.CanCollide == true then
					if player ~= nil then
						if script.Parent.Owner.Value == player then
							if hit.Parent:FindFirstChild("Humanoid") then
								if hit.Parent.Humanoid.Health > 0 then
									local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
									if PlayerStats ~= nil then
										if (v:FindFirstChild('Gamepass')) and (v.Gamepass.Value >= 1) then
											if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,v.Gamepass.Value) then
												Purchase({[1] = v.Price.Value,[2] = v,[3] = PlayerStats})
											else
												game:GetService('MarketplaceService'):PromptPurchase(player,v.Gamepass.Value)
											end
										elseif (v:FindFirstChild('DevProduct')) and (v.DevProduct.Value >= 1) then
											game:GetService('MarketplaceService'):PromptProductPurchase(player,v.DevProduct.Value)
										elseif PlayerStats.Value >= v.Price.Value then
											Purchase({[1] = v.Price.Value,[2] = v,[3] = PlayerStats})
											Sound(v, Settings.Sounds.Purchase)
										else
											Sound(v, Settings.Sounds.ErrorBuy)
										end
									end
								end
							end
						end
					end
				end
			end)
			end
		end)
	end
	
	function Purchase(tbl)
		local cost = tbl[1]
		local item = tbl[2]
		local stats = tbl[3]
		stats.Value = stats.Value - cost
		Objects[item.Object.Value].Parent = script.Parent.PurchasedObjects
		if Settings['ButtonsFadeOut'] then
			item.Head.CanCollide = false
			coroutine.resume(coroutine.create(function()
				for i=1,20 do
					wait(Settings['FadeOutTime']/20)
					item.Head.Transparency = item.Head.Transparency + 0.05
				end
			end))
		else
			item.Head.CanCollide = false
			item.Head.Transparency = 1
		end
	end
	
	function Create(tab)
		local x = Instance.new('Model')
		Instance.new('NumberValue',x).Value = tab[1]
		x.Value.Name = "Cost"
		Instance.new('ObjectValue',x).Value = tab[2]
		x.Value.Name = "Button"
		local Obj = Instance.new('ObjectValue',x)
		Obj.Name = "Stats"
		Obj.Value = tab[3]
		x.Parent = script.Parent.BuyObject
	end
	
	--// This was very rushed and is inefficent; if you plan on making something like this don't use a child added listener.
	script.Parent:WaitForChild('BuyObject').ChildAdded:connect(function(child)
		local tab = {}
		tab[1] = child.Cost.Value
		tab[2] = child.Button.Value
		tab[3] = child.Stats.Value
		Purchase(tab)
		wait(10)
		child:Destroy()
	end)

And the Settings file:

local module = {
	['Sounds'] = {
		['Purchase'] = 203785492, -- The sound that plays when a player buys a button he can afford
		['Collect'] = 131886985, -- The sound that plays when a player collects his currency
		['ErrorBuy'] = 138090596 -- The sound that plays when a player buys a button he can't afford
	},
	['AutoAssignTeams'] = false, -- If set to false the player will join on a 'hire' team and will pick their own tycoon
	['CurrencyName'] = "Cash", -- The name of your currency inside the tycoons; this will show up everywhere.
	['ButtonsFadeOut'] = true,
	['FadeOutTime'] = 0.5,
	['ButtonsFadeIn'] = true,
	['FadeInTime'] = 0.5,
	['LeaderboardSettings'] = {
		['KOs'] = true, -- KnockOuts will show on the leaderboard
		['KillsName'] = "Kills", -- What will you call the kills
		['WOs'] = true,-- Wipeouts will show on the leaderboard
		['DeathsName'] = "Deaths", -- What will you call the deaths
		['ShowCurrency'] = true, -- Will show player's money to others
		['ShowShortCurrency'] = true -- This will change a players cash from showing "100,000" to "100K"
	},
	['StealSettings'] = {
		['Stealing'] = true, -- If this is set to true, you can step on other player's collectors and steal a precent indeciated below from the player!
		['StealPrecent'] = 0.25, -- This is the precent of their currency you can take! (1 = all of the currency)
		['PlayerProtection'] = 60 -- This is the time in seconds in which the player can not be stolen from
	}
}












function module:ConvertComma(num)
	local x = tostring(num)
	if #x>=10 then
		local important = (#x-9)
		return x:sub(0,(important))..","..x:sub(important+1,important+3)..","..x:sub(important+4,important+6)..","..x:sub(important+7)
	elseif #x>= 7 then
		local important = (#x-6)
		return x:sub(0,(important))..","..x:sub(important+1,important+3)..","..x:sub(important+4)
	elseif #x>=4 then
		return x:sub(0,(#x-3))..","..x:sub((#x-3)+1)
	else
		return num
	end
end

function module:ConvertShort(Filter_Num)
	local x = tostring(Filter_Num)
	if #x>=10 then
		local important = (#x-9)
		return x:sub(0,(important)).."."..(x:sub(#x-7,(#x-7))).."B+"
	elseif #x>= 7 then
		local important = (#x-6)
		return x:sub(0,(important)).."."..(x:sub(#x-5,(#x-5))).."M+"
	elseif #x>=4 then
		return x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
	else
		return Filter_Num
	end
end

return module

I’ve had troubles with the same thing. I’ll have to see if mine was fixed.

Ill update you if I solve it.

Double check if you have two PurchaseHandler scripts and are editing both of them. Since I have Zed’s tycoon modified with the AutoSave script I have to edit both.

The Sound.MaxDistance = 20 should work. Since the sound is parented to the part.

1 Like

Yes, I have 2 tycoons for testing. So in each tycoon is a purchasehandler script… But unfortunately maxdistance doesn’t work for me… Edit: yes, I have a save Trigger file added to my tycoons…

If the volume changing doesn’t work, then it is certainly not coming from the Sound function. I’ll take a look whenever I can. Do you just have two tycoons near each other?

1 Like

Yes, the tycoons are close to each other but I tried to move them away as possible and opened roblox on mobile with a second account to test the sound. Doesn’t matter how far the players are from each other… I saw another topic on this matter were the guy fix the problem but did not showed how he did it…

Well,
try it with the SoundService, the Replicated Storage and the Client.

  1. Insert 3 Sounds in SoundService
  2. Name the Sounds “Collect”, “Purchased” and “ErrorBuy” and fill the Sound Id (With the Settings Sound IDs.
  3. Go to StarterPlayer and StarterPlayer Scripts and Insert a Local Script.
  4. Go to Replicate Storage and Insert a Remote Event with the Name “PlayMusic”
  5. Now go to the script in StarterPlayer and “past” this code:
local RS = game.ReplicatedStorage
local PlayMusic = RS:FindFirstChild(“PlayMusic”)
local deb = false
PlayMusic.OnClientEvent:connect(function(sound)
if game.SoundService:FindFirstChild(sound) then
local S = game.SoundService:FindFirstChild(sound)
if deb == false then
deb = true
S:Play()
delay(S.TimeLength, function()
S.Stop()
deb = false
     end)
  end
 end
end)
  1. You must change your PurchaseHandler Code
    First: Add “local PlayMusic = game.ReplicatedStorage:FindFirstChild(“PlayMusic”)” (line 8)
    2nd: You have something that triggered the function “Sound”. Go there and past this code:
PlayMusic:FireClient(player, "Music here!") — Music here (the name (Collect,ErrorBuy, Purchased))
  1. In the Purchase Handler you have this script:
function Sound(part,id)
		if part:FindFirstChild('Sound') then
			return
		else
			local Sound = Instance.new('Sound',part)
			Sound.SoundId = "rbxassetid://"..tostring(id)
			Sound:Play()
			delay(Sound.TimeLength, function()
				Sound:Destroy()
			end)
		end
	end

Delete this code.

I hope I could help!

4 Likes

Had the same problem, I hired someone who improved it. You can only hear the sound in a 5m radius.

Yes, but if someone is in that 5m “radius” they hear it.

Exactly, thats what i wanted. If someone is bothered by it he can just leave the tycoon from the other person.

1 Like

Just wow!
So with a few minor adjustments it worked! Thanks for helping. If anyone else can’t make it work let me know! Oetzi_CS you made my day!

Edit for someone else with this problem:
Delete this code in PurchaseHandler(if you have savetrigger for all the tycoons and inside savetrigger file:

	function Sound(part,id)
		if part:FindFirstChild('Sound') then
			return
		else
			local Sound = Instance.new('Sound',part)
			Sound.SoundId = "rbxassetid://"..tostring(id)
			Sound:Play()
			delay(Sound.TimeLength, function()
				Sound:Destroy()
			end)
		end
	end

Press ctrl+f and search for the word : Sound
You will find a couple of rows like this:
Sound(script.Parent.Essentials, Settings.Sounds.Collect)
Delete that row and past one of the lines below ( for collect ofc Collect etc.)

PlayMusic:FireClient(player, “Collect”) 
PlayMusic:FireClient(player, “Purchased”) 
PlayMusic:FireClient(player, “ErrorBuy”)

Thanks (Legend) Oetzi_CS

4 Likes

Hey there,
I just fixed an critical issue in my code. You should definitely change that.


Also Sorry for bumping

Thanks Oetzi_CS! My game is closer to releasing! I have a new Zed tycoon version (plasboer or sm like that) so all the solutions in this post did not help me, even yours… But with a few minor changes it worked! For those using the same version as me, Do not delete any scripts codes, It will break the script! Just follow what Oetzi said but without deleting stuff and changing the ID numbers in settings to 123 (So it wont play) , then you will have to past the - PlayMusic:FireClient(player, “CollectOrErrorbuyOrPurchased”) under these scripts - local PlayMusic = game.ReplicatedStorage:FindFirstChild(“PlayMusic”)