The script itself works flawlessly, however, the sound only plays on the client, not in the server. This is a problem because it makes the script (which purpose is for locating other players) entirely useless
local Player = script.parent
local function playSound()
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120675904"
sound.Parent = game.Workspace
sound:Play()
end
local onCooldown = false
local cooldownTime = 2
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.T and not onCooldown then
onCooldown = true
playSound()
task.delay(cooldownTime, function()
onCooldown = false
end)
end
end)
local Player = script.parent
local function playSound()
game.ReplicatedStorage.WhistleEvent:FireServer(Player)
end
local onCooldown = false
local cooldownTime = 2
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.T and not onCooldown then
onCooldown = true
playSound()
task.delay(cooldownTime, function()
onCooldown = false
end)
end
ServerScript:
game.ReplicatedStorage.WhistleEvent.OnServerEvent:Connect(function(Player)
if not Player.Character then
repeat wait() until Player.Character
end
local clone = script.WhistleSound:Clone()
clone.Parent = Player.Character.Head
clone:Play()
clone.Stopped:Wait() -- this might not be correct. event names for when things stop are a lil uneven.
clone:Destroy()
end)