what is that supposed to mean?
Like I wrote it, so for example:
button.MouseButton1Click:Connect(function()
script
end)
By hierarchy I meant basically your explorer Window
Oh I found the bug, your variable is spelled sound but in the function the S is capital
My bad, typo!
Hmm. I cant seem to put Connect in it. Im trying this btw:
local Sound = script:WaitForChild("trr")
local button = game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
input.KeyCode == Enum.KeyCode.Z
local Activated = false
end
button:Connect(function()
if Activated == false and Sound.Playing == false then
Sound:Play
Sound.Looped = true
Activated = true
elseif Activated == true and Sound.Playing == true then
Sound:Destroy()
Sound.Looped = false
Activated = false
end)
end)
i fixed the capital
- Activated variable is inside of uis function
- The button:Connect isnt enough, as you need to specify when the function connects
How do i specify when the function connects?
Like for example, if you write what needs to happen for the function to connect, so for example button.MouseButton1Click:Connect(function()ā¦end)
Here we see that the function fires once the button has been clicked
Its supposed to toggle when you press z
Yeah then you need to replace button.MouseButton1Click with your keycode
wait i got lost. what is the button variable supposed to be then?
It was just a placeholder for your key
what is my key? Also sorry for being so clueless, im a beginner. I hope it does not bother you.
No it doesnāt bother me, trust me, Iāve been there a couple months ago.
With the key, i mean your Z key (the one you want to be pressed for the sound to play!)
Btw I can send you a full script later when I have time, cuz right now I have to do homework and I see our conversation getting longer and longer.
k. thanks for the help though!
Hello, sorry for the late reply, I will be able to provide you with a script in about half an hour
hey there, Iāve been trying to get this to work for the last 30 minutes, unfortunately it still doesnt. I changed the code a whole lot, this is what I ended up with:
local UIS = game:GetService("UserInputService")
local key = "Z"
local Sound = script:WaitForChild("Sound")
local Activated = false
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode[key] then
if Activated == false and Sound.Playing == false then
Sound:Play()
Sound.Looped = true
Activated = true
elseif Activated == true and Sound.Playing == true then
Sound:Destroy()
Sound.Looped = false
Activated = false
end
end
end)
Again, Iām sorry for wasting your time. If you have any ideas how to make it work, feel free to reach out to me and I will happily try to help you once again!
Best regards,
AlexPalex178
Sounds have to be parented to a Part or Attachment to play from just that Part and you can change the distance itāll be heard from.
If the sound is in the Workspace (anyhwhere not in a Part or Attachment itāll play everywhere in the game. I havenāt tried putting it in a script though.