-- play random horror sounds (coded by mich)
local horrorsoundsFolder = game.Workspace.HORRORSOUNDS
local horrorsoundsCount = 1 -- the max amount of horror sounds that can be played at once
-- note: changing the count more than horror sounds in HORRORSOUNDS folder can cause "not a valid member" error
local Random = math.random(1, horrorsoundsCount) -- this variable will be used for choosing random number
while true do
wait(20) -- just wait for a while before playing one
horrorsoundsFolder.HORROR[Random].Playing = true
print("Random horror sound is played")
-- you can change the horrorsoundsCount if you added new horror sound -mich
end
#need help with this bug.
1 messages · Page 1 of 1 (latest)
Output:
11:45:16.392 Stack Begin - Studio
11:45:16.393 Script 'Workspace.Cupcake.Script', Line 119 - Studio - Script:119
11:45:16.393 Stack End - Studio
HORROR is not something in the HORRORSOUNDS folder
for some reason it skips "Random" variable
look, its supposed to choose random number after "HORROR"
horrorsoundsFolder[Random].Playing = true
HORROR dosn't existe, you only have "HORROR1" and if you want to select a child with the ID you put it in de folder name
horrorsoundsFolder[Random].Playing = true
it was suppposed to choose random number after the name "HORROR", if you look at horrorsoundsCount variable and Random variable, you'll see the problem
If you have more than one sound in the floder its going to chose one between 1 and 1 so the Random variable its Useless
** You are now Level 2! **
okay well im gonna add another horror sound and see if this problem is fixed
Try to do that (i don't know if its work )
horrorsoundsFolder["HORROR".. Random].Playing = true
hang on let me test first then try your suggestion
Bruh another AI generated script
Or create local variable before like this
local horrorsoundsFolder = game.Workspace.HORRORSOUNDS
local horrorsoundsCount = 2 -- the max amount of horror sounds that can be played at once
-- note: changing the count more than horror sounds in HORRORSOUNDS folder can cause "not a valid member" error
local Random = math.random(1, horrorsoundsCount) -- this variable will be used for choosing random number
while true do
wait(20) -- just wait for a while before playing one
local newSoundPath = "HORROR".. Random
horrorsoundsFolder[newSoundPath].Playing = true
print("Random horror sound is played")
-- you can change the horrorsoundsCount if you added new horror sound -mich
end
Do you even know what the script does ?
ok it didnt work
its not ai generated
i added some messages to the script
i coded it
alr lemme try this
Sure
btw i was helping my friend on his own game
bruh look, no ai
the script is inside the cupcake pet
Why did you ping me for an insignificant picture
oh sorry i didnt turn off ping
It's work
You have to reset RANDOM variable every time you want to change the sound
wait it worked
** You are now Level 3! **
it did work with this one
local horrorsoundsFolder = game.Workspace.HORRORSOUNDS
local horrorsoundsCount = 2
while true do
wait(2) -- just wait for a while before playing one
local Random = math.random(1, horrorsoundsCount)
local newSoundPath = "HORROR".. Random
horrorsoundsFolder[newSoundPath].Playing = true
end
The last i send its better
btw that game is made by my friend but for some reason he used ai to code horror mode function so yeah idk why
This one its not realy work becouse its not re set the Random Value
Another day another one of these
is there something wrong?
let me explain this, so firstly i added variables that gets horror sounds folder then another variable which keeps track of how many horror sounds are there in the folder. theres also random variable that chooses from 1 to horrorsoundsCount (which is 2). Then it enters the loop where it waits for while then plays random horror sound, btw i also added print because i want to know if my code is working correctly (or just for debugging). So do you believe me now? (sorry for ping 😦 )
It's work ?
yes
it worked with ["HORROR".. Random]
I but i recommand you this one
ok
there changed it, now for last test then ill remove that print statement
btw do u want to see the horror game that my friend made (thats with my code that plays random horror sounds)?
@lucid vigil for some reason, the horror sounds keeps playing without waiting for 50 seconds
You can still use wait(50) or task.wait(50) but I recommande this :
task.wait(50)? alr
what do you recommend?
@lucid vigil it still plays sounds without waiting
local horrorsoundsFolder = game.Workspace:WaitForChild("HORRORSOUNDS")
local horrorsoundsCount = 2
local currentSound = nil
task.wait(1)
while true do
if currentSound ~= nil then
wait(50)
currentSound = nil
else
local Random = math.random(1, horrorsoundsCount)
local newSoundPath = "HORROR".. Random
currentSound = horrorsoundsFolder[newSoundPath]
horrorsoundsFolder[newSoundPath].Playing = true
warn("Playing sound : " ..currentSound.Name)
end
end
@static birch use that to see
modifie task.wait if you want to put 1 seconde
I Updated the script
** You are now Level 3! **
ok ill test
@lucid vigil heres output:
13:17:48.075 Stack Begin - Studio
13:17:48.075 Script 'Workspace.Cupcake.Script', Line 113 - Studio - Script:113
13:17:48.075 Stack End - Studio
new update
k
** You are now Level 4! **
it still wont wait for 20 secs @lucid vigil
13:24:40.492 Playing sound : HORROR2 - Server - Script:128
13:24:43.858 Playing sound : HORROR1 - Server - Script:128
13:24:49.359 Playing sound : HORROR2 - Server - Script:128
Its depend of the lenght of the sound @static birch
If the sound don't finish its won't start another
but its supposed to wait for 50 seconds after the horror sound is over then plays another horror sound
Update
I could'nt do more
So ?
okay it still didnt wait
it waited until the horror sound is over then plays another
i dont know why roblox studio is doing this to us
ok lemme try to fix it
ok! say me if you are make it done
lemme recode it
can u join vc and watch me code it?
why dont u just use the # of sounds in the folder to determine what can be played randomly? in your original code your max sounds played at once doesnt determine how many sounds can be played at once, but how many sounds you have in the folder (which could be inaccurate) so u sometimes get the not a member error
well i did use "#" but it resulted in error
plus, I'm gonna recode it right now i guess
local horrorsoundsFolder = game.Workspace.HORRORSOUNDS
local Random = math.random(1, #horrorsoundsFolder:GetChildren()) --
while true do
wait(2) -- just wait for a while before playing one
horrorsoundsFolder:GetChildren()[Random].Playing = true
print("Random horror sound is played")
end
ok ill try that
lowkey could be improved but i feel the original is more demonstrative of what is going on, heres how i would leave it:
local tableofsounds = game.Workspace.HORRORSOUNDS:GetChildren()
while true do
local Random = math.random(1, #tableofsounds ) --
wait(2) -- just wait for a while before playing one
tableofsounds[Random].Playing = true
print("Random horror sound is played")
end
oh also i forgot to make the random call in the while loop, make sure thats in there or ur gonna get the same sound every time
ok ill try that one
also depending on if u want the sound to restart or not u could do :Play() instead of .Playing = true
lemme try with wait(50)
@crisp cosmos for some reason, after 50 seconds it plays horror sounds too quickly without waiting for 50 seconds
13:59:52.944 Random horror sound is played
13:59:56.892 Random horror sound is played```
what if i put this piece of script in module script then let the main script trigger it
lemme try my idea, be right back
are u sure ur not calling this piece of code several times
is this like an independent script or is something calling a function that does this
i think it was in a code that triggers a lot of times
btw heres module script, does this look good?
local PlayRandomHorrorSounds = {}
-- play random horror sound remake (by mich)
local tableofsounds = game.Workspace.HORRORSOUNDS:GetChildren()
function PlayRandomHorrorSounds.Trigger()
-- play random horror sound remake (by mich)
local tableofsounds = game.Workspace.HORRORSOUNDS:GetChildren()
while true do
local Random = math.random(1, #tableofsounds ) --
wait(50) -- just wait for a while before playing one
tableofsounds[Random].Playing = true
print("Random horror sound is played")
end
end
return PlayRandomHorrorSounds
makes sense, it shows up pretty regularly every 4 seconds
if i was approaching making a module to play horror sounds i would personally remove the waits and the while loop from the module
since the idea is flexibility, im going to remove as many things that restrict me as possible
that would leave me with a module that, for example, could produce a horror sound from a preset list anywhere (without locking me in to doing it forever every 50 seconds)
also when making a module script and making a function that can be used by other code you need to declare it differently. we need to add it to the table that we return when the module is required, so like this:
in main script:
local PlayRandomHorrorSoundsModule = game.Workspace.PlayRandomHorrorSounds
-- rest of code
-- play random scary ahh sounds module
PlayRandomHorrorSoundsModule.Trigger()
-- rest of code
local PlayRandomHorrorSounds = {}
PlayRandomHorrorSounds.Trigger = function(partToPlayIn)
--update potential sounds every time we do this
local tableofsounds = game.Workspace.HORRORSOUNDS:GetChildren()
local Random = math.random(1, #tableofsounds)
if partToPlayIn then
local specificplace = tableofsounds[Random]:Clone()
specificplace.PlayOnRemove = true
specificplace.Parent = partToPlayIn
specificplace:Destroy()
else
tableofsounds[Random]:Play()
end
end
return PlayRandomHorrorSounds
so is the sound supposed to be like
an abstract sound or come from a specific part?
yeah uh after playing the sound, it waits for 50 seconds before playing another one
i mean like do they hear it come from somewhere specific is the idea
or just all around them
the sounds play in workspace itself in folder HORRORSOUNDS
idk maybe join vc and ill show you?
so the module i just made has the option of doing either
if you call Trigger(part) it will place it in that specific part
in the regular script you would do this:
local soundmodule = require(blah.PlayRandomHorrorSounds)
while true do
task.wait(50)
soundmodule.Trigger()
end
what?? but i did same thing as in my other horror game and it worked, but it doesnt work in this version
14:18:47.814 Trigger is not a valid member of ModuleScript "Workspace.PlayRandomHorrorSounds" - Server - Script:115
14:18:47.814 Stack Begin - Studio
14:18:47.814 Script 'Workspace.Cupcake.Script', Line 115 - Studio - Script:115
14:18:47.814 Stack End - Studio
how is it not valid member?
i just did Trigger()
bru I made one of the most common beginner mistakes, wrong symbol..
** You are now Level 5! **
instead of . i changed it to :
rip
and same error
post code
"Trigger is not a valid member of ModuleScript"
it points to this line
PlayRandomHorrorSoundsModule:Trigger()
you didnt require the module
forgot to put require(
i looked at script in my other horror game
yeah i realized that
test #unknown (i lost count)
bro i swear to god i did not type that
@crisp cosmos the bug didnt get fixed, it still plays sounds too quickly
ill try this
oh wait theres a mistake, ill fix it
fixed
@crisp cosmos another error, i have no idea why roblos studio is even doing this to us
14:50:03.540 Stack Begin - Studio
14:50:03.540 Script 'Workspace.PlayRandomHorrorSounds', Line 10 - function Trigger - Studio - PlayRandomHorrorSounds:10
14:50:03.540 Script 'Workspace.Cupcake.Script', Line 115 - Studio - Script:115
14:50:03.540 Stack End - Studio```
show the whole code
ok
local PlayRandomHorrorSounds = {}
function PlayRandomHorrorSounds.Trigger(partToPlayIn)
--update potential sounds every time we do this
local tableofsounds = game.Workspace.HORRORSOUNDS:GetChildren()
local Random = math.random(1, #tableofsounds)
if partToPlayIn then
local specificplace = tableofsounds[Random]:Clone()
specificplace.PlayOnRemove = true
specificplace.Parent = partToPlayIn
specificplace:Destroy()
else
tableofsounds[Random]:Play()
end
end
return PlayRandomHorrorSounds
what are you passing as partToPlayIn
i literally copied your code
this code
do i place "partToPlayIn" inside that
not necessarily
its optional and lets you specify a part in the workspace for the sound to come out of
but i dont want to specify a part in workspace
i wanted the horror sounds to actually play in the background
okay lemme use this once again
local PlayRandomHorrorSounds = {}
-- play random horror sound remake (by mich)
local tableofsounds = game.Workspace.HORRORSOUNDS:GetChildren()
function PlayRandomHorrorSounds.Trigger()
-- play random horror sound remake (by mich)
local tableofsounds = game.Workspace.HORRORSOUNDS:GetChildren()
while true do
local Random = math.random(1, #tableofsounds ) --
wait(50) -- just wait for a while before playing one
tableofsounds[Random].Playing = true
print("Random horror sound is played")
end
end
return PlayRandomHorrorSounds
I STILL DONT UNDERSTAND
15:48:55.716 Random horror sound is played
15:49:02.414 Random horror sound is played
15:49:06.931 Random horror sound is played```
EVEN WITH wait(50) IT JUST DOESNT WAIT
okay i think roblox studio hates me
also even the whole main script that my friend put is made by AI, so i dont even understand what the code literally does unless I ask him. But hes not online
@crisp cosmos do you understand what the main script (not module script) does? because i dont
oh i finally figured it out, it turns out that it triggered the module script everytime i press on cupcake
What is your friend trying to do ?
Is he trying to make a game or to learn scripting ?
Either way he’s wasting his time if he attempts to succeed in any of the options above.
Bro my friend came then told me that my code broke cupcake the cat teleport function
It literally was only playing a horror sound
And how can I help ?
Bruh he said that ai is making tween function
** You are now Level 6! **
Well he said that there was infinite yield error but I didn't get that error when I tested my code
It's possible that the ai is messing up the code or smth
Send script
But he literally removed that function completely
I mean it’s AI
What were y’all expecting besides destroying your own project with AI ?
Well I have to recode it all over again and I still remember how to code that
Well his horror game worked so perfectly
Like uh there was no error, but if someone used AI then it means they are lazy
Brb I'ma code my function
Exactly
Well I did use ai before but I have learned some lua scripts from the ai
I think the ai is used for learning lua
Not coding the lua
I'ma code it then send the script
@floral gale heres the code that i wrote by myself:
-- play some random ahh spooky sounds remake edition (by mich)
local HORRORSOUNDSFolder = game.Workspace.HORRORSOUNDS
local HORRORSOUNDSCount = #HORRORSOUNDSFolder:GetChildren()
local randomHorrorSoundsSELECT = math.random(1, HORRORSOUNDSCount)
local newHorrorSoundPATH = "HORROR".. HORRORSOUNDSCount
HORRORSOUNDSFolder[newHorrorSoundPATH].Playing = true
oh wait i messed up something!
heres fixed code:
-- play some random ahh spooky sounds remake edition (by mich)
local HORRORSOUNDSFolder = game.Workspace.HORRORSOUNDS
local HORRORSOUNDSCount = #HORRORSOUNDSFolder:GetChildren()
local randomHorrorSoundsSELECT = math.random(1, HORRORSOUNDSCount)
local newHorrorSoundPATH = "HORROR".. randomHorrorSoundsSELECT
HORRORSOUNDSFolder[newHorrorSoundPATH].Playing = true
lemme test