Hello developers!
I’m having some problems with a function.
function music()
if script.Parent.Value == "Intruder Alert" then
wait(10)
script.Parent.Parent.Parent.MeltdownManager["Project Borealis | Breach"]:Play()
end
end
music()
It cannot recognize the StringValue: “Intruder Alert”. I’ve already tried modifying the code by adding a two-step value check:
if X.Value == "X" and Y.Value == "Y" then
But it didn’t worked either.
I honestly don’t know what else I can do about it.
Please help me fix this problem.
Thank you! Have a great day
Because this is the Scripting support forum, you’ll have to be more descriptive about the event that lead up to the codes, what you’re trying to achieve, and much more broader view of the code. Also, send a picture of the explorer around the area where it involves it (ancestor-wise)
Using a StringValue to keep track of the sounds is a bad idea. Ideally, you could create a function that plays an specific sound:
local IntruderAlertSfx = ...
local function playIntruderAlertSfx()
intruderAlertSfx:Play()
end
Also, DRY (don’t repeat yourself). You could create a variable to MeltdownManager once, instead of doing script.Parent.Parent.Parent.MeltdownManager dozens of times.
local MeltdownManager = script.Parent.Parent.Parent.MeltdownManager
Although, this isn’t much better. It would be nice to also keep track of what script.Parent, script.Parent.Parent and what script.Parent.Parent.Parent are.
Lastly, I think you should better structure / organize your game assets.
I understood your explanation, but I didn’t understand what changes I should make. Can you rewrite the script completely with your modifications or re-explain it a little more clearly? (Obviously if you want)
In terms of organization, it is very well organized into several folders
(I only have this in my testing world)
I just need the script and the function to recognize the StringValue and perform a specific function.
You don’t even need to completely rewrite the code, just making the recognize function would help me a lot.
PS: I’m not using MeltdownManager anymore, I’m using a script inside of ProtocolStatus
Talvez o problema seja que você está tentando tocar o som fora da Workspace. Tenta clonar o som antes de tocar ele ou parenteia ela para a Workspace antes da função rodar.