I know this part if (Key:lower() == "e") then
then i did this if (Key:lower() == "e") then --- detect the button pressing game.Workspace.Sound:Play() --- plays the sound end
and it doesn't work
im a new scripter/dev
I know this part if (Key:lower() == "e") then
then i did this if (Key:lower() == "e") then --- detect the button pressing game.Workspace.Sound:Play() --- plays the sound end
and it doesn't work
im a new scripter/dev
Hello, yogamer13294456!
You have to create the audio block and then try to play it!
Your script should be something like:
-- Local Script
local SoundToPlay = 00000000 -- Change the "00000000" to the sound id
audio = Instance.new("Sound") -- Creates the sound block
audio.Parent = game.Workspace -- Changes the sound block Parent
audio.SoundId = "http://www.roblox.com/asset/?id=" .. SoundToPlay -- Changes the sound to play
function onKeyPress(inputObject, gameProcessedEvent) -- Function when player press any key
if inputObject.KeyCode == Enum.KeyCode.E then -- Tests if key is equals E
audio.TimePosition = 0
audio:Play()
end
end
game:GetService("UserInputService").InputBegan:Connect(onKeyPress) -- Detects player input
Place the script above on the "Starter Player Scripts"
Good Luck with your games!
Thanks!
First put that script in a local script, and then put it in Starter Player Scripts If that doesnt work then use mine which is:
local music = game.Workspace.Audio
function onKeyPress(actionName, userInputState, inputObject)
if userInputState == Enum.UserInputState.Begin then
music.TimePosition = 0 --we want it to start at the beggining--
music.Playing = true
end
end
game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.E)
PS: Remember to put mine in a local script and StarterPlayerScripts. Also use variables more often they save a lot of time!
I thought Playing is a read-only value.
Playing is a property of any sound
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
put it in a codeblock
whats a code block
a code block is a chunk of code defined by what "enclosure" it is in: https://imgur.com/a/PGH1F