This thread needs significantly more details, please provide them - code, errors, issues you’ve identified and so on. Additionally, please do make sure you reference the Developer Hub for articles and API so you at least have some baseline knowledge on how to perform certain actions on the platform, such as playing sounds (see: Sound).
Server script:
script.Parent.Fire.OnServerEvent:Connect(function(player,mousePos)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*300,raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid")then
model.Humanoid.Health -=50
end
end
end
end)
Client script:
local mouse = game.Players.LocalPlayer:GetMouse()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*300,raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid")then
model.Humanoid.Health -=20
end
end
end
end)
I want to add it to the server script, where should the line of code go?
Place the sound in a part or an attachment. That wil give it the effect off emanating from that part.
More info you can read here Sound | Roblox Creator Documentation
So you could just simply reference the Sound as player.Character.Tool.Sound, and play it when the OnServerEvent detects the event being fired
script.Parent.Fire.OnServerEvent:Connect(function(player,mousePos)
player.Character.Tool.Sound:Play()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(mousePos -
script.Parent.Handle.Position)*300,raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local model = hitPart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid")then
model.Humanoid.Health -=20
end
end
end
end)
If you wanted the play the Sound at a certain distance, you’d need to parent it inside a BasePart of some sort