Ok so i have been trying to make a script where when you press a KeyBind your character plays a sound effect that everyone around you can hear coming from the players location
currently the LocalScript triggers a RemoteEvent to a ServerScript in StarterCharacterScripts that then gets the player and plays the sound, it works but my problem is only one person at a time can be playing a sound, there’s a 0.2 second delay so it cant spam it but when other players also press it they have to wait 0.2 seconds from the first person so two people cant do it at the same time.
Local Script
local keyPressed = Enum.KeyCode.F
local remote = game.ReplicatedStorage.BeepRemote
local cooldown = false
local userInputService = game:GetService("UserInputService")
-- Sends KeyPress To Server Script
userInputService.InputBegan:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == keyPressed then
if cooldown == false then
cooldown = true
remote:FireServer()
wait(0.2)
cooldown = false
end
end
end)
print("BeepLocalScriptLoaded")
So the way I have it set up is that when you press the KeyBind it sends a signal to the ServerScript using a RemoteEvent
Server Script
-- Tweening Settings
local tweeneasing = Enum.EasingStyle.Circular
local tweentime = 1.5
local effectgoalsize = UDim2.new(1, 0,1, 0)
local effectgoalposition = UDim2.new(0, 0,0, 0)
-- Locals
local character = script.Parent
local head = character:WaitForChild("Head")
local root = character:WaitForChild"HumanoidRootPart"
local storage = game:GetService("ReplicatedStorage")
local remote = storage:WaitForChild("BeepRemote")
local tween = game:GetService("TweenService")
local effect = storage.BeepEffect
local cooldown = false
-- Creating Effect
local cloneeffect = effect:Clone()
cloneeffect.Parent = head
print("Effect Created")
-- Creating Sound
local beep = Instance.new("Sound")
local pitch = Instance.new("PitchShiftSoundEffect")
local speed beep.PlaybackSpeed = 1
beep.Parent = root
beep.Name = "Beep"
beep.SoundId = "rbxassetid://17155242113"
beep.Volume = .5
beep.RollOffMaxDistance = 30
beep.RollOffMinDistance = 5
pitch.Name = "Pitch"
pitch.Parent = root.Beep
pitch.Octave = 1
print("Sound Created")
-- play sound when getting signal from local script
remote.OnServerEvent:Connect(function(player)
local character = script.Parent:FindFirstChild("Humanoid")
if cooldown == false then
if character.health >= 1 then
cooldown = true
local character = player.Character
local head = character:WaitForChild("Head")
local root = character:WaitForChild"HumanoidRootPart"
-- Playing Sound
local beep = root:WaitForChild("Beep")
local pitch = beep:WaitForChild("Pitch")
speed = math.random(1, 5)/15
pitch.Octave = math.random(7.5, 11)/8
beep:Play()
-- Playing Effect
local cloneeffect = head:WaitForChild("BeepEffect")
local cloneimage = cloneeffect:WaitForChild("BeepTexture")
cloneeffect.Enabled = false
cloneimage.Position = UDim2.new(0.5, 0,0.5, 0)
cloneimage.Size = UDim2.new(0, 0,0, 0)
cloneimage.ImageTransparency = 0
local goal = {}
goal.Position = effectgoalposition
goal.Size = effectgoalsize
goal.ImageTransparency = 1
local tweenInfo = TweenInfo.new(speed + 1, tweeneasing)
local tween1 = tween:Create(cloneimage, tweenInfo, goal)
cloneeffect.Enabled = true
tween1:Play()
print(player, "Beeped At", pitch.Octave, "Pitch &", speed, "Speed Plus", speed + 1, "Tween Speed")
wait(0.2)
cooldown = false
else
end
end
end)
print("BeepServerScriptLoaded")
Currently it creates a sound in the players humanoid root part and plays it from there the “Beep” is the sound effect, then when it gets a signal from the RemoteEvent it gets the local character and finds the “Beep” then plays it
the Tween is for a effect that plays don’t worry about it,
your welcome to use the script if you want but idk why you would xd
I have tried some random things and looked a bit on the DevForum but to no avail