So i am trying to make sound play when player touches it and only the player who touches the block heares the “Scream sound”.
local played = false
script.Parent.Touched:Connect(function(hit)
if played == false then
workspace.SoundLibrary.Scream:Play() --these are Sounds and The Folder in the workspace
played = true
wait (5)
played = false
end
end)
So will i create RemoteEvent and put it to replicatedstorage then put this script
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local remoteEvent = ReplicatedStorage:WaitForChild(“RemoteEventTest”)
– Fire the remote event
remoteEvent:FireServer()
in local script serverscriptservice then
make my script
local played = false
remoteEvent:FireServer.script.Parent.Touched:Connect(function(hit)
if played == false then
workspace.SoundLibrary.Scream:Play() --these are Sounds and The Folder in the workspace
played = true
wait (5)
played = false
end
end)
you can make the localscript in playerscripts and edit the path of touched event like game.Workspace["Part"].Touched for example and you should be good to go
Yes, just create a new LocalScript, put it inside the part that makes the Scream sound when you touch and make the script play that sound after you touch it, because we’re using LocalScript that will only be heard to the LocalPlayer (Client / Your Computer).
local played = false
script.Parent.Touched:Connect(function()
if played == false then
workspace.SoundLibrary.Scream:Play()
played = true
wait (5)
played = false
end
end)
this won’t work due to limitation of localscript see here localscript limit
you need either putting it in backpack or the character or playerscripts or playergui correct me if i am wrong
local played = false
script.Parent.Touched:Connect(function(hit)
if not played then
workspace.SoundLibrary.Scream:Play()
played = true
wait(5)
played = false
end
end)
Oh yes, my mistake, you’re absolutely right. You need to put the LocalScript inside an object that the LocalScript has access to. Places such as StarterPlayer, StarterCharacterScripts, StarterPlayerScripts, StarterGui, StarterPack…
You could just make that script on the client if you aren’t aware of how remotes work. To do this simply just make a LocalScript, create the audio inside the script locally, then play it when someone touches it.