This script won’t trigger, i know that because line 5 doesn’t print anything in the ouput, there is also no errors, code is inside a ServerScript inside a textButton.
plrs.PlayerAdded:Connect(function(player)
script.Parent.MouseButton1Click:Connect(function(triggered)
print("lol")
if player.Character:FindFirstChild("Humanoid") then
player.Character:WaitForChild("Head"):FindFirstChild("Screaming"):Play()
end
end)
end)
Use a LocalScript instead of a ServerScript.
Remove the triggered parameter in MouseButton1Click function, i don’t see that you really need to use that for the code you’re trying to write.
Remove the PlayerAdded part, it is not required.
If you want to define the player so much, write:
local player = game.Players.LocalPlayer
And then, If you want to make the sound heard by everyone create a Remote Event and Fire it.
Receive the information on server and play the audio there.
I take it you have a way set up to move the scream sound to the head all ready is that correct?
Well … if so:
In ReplicatedStorage create a RemoteEvent and name it Screaming
Place script A in StarterGui
Place script B on the workspace or ServerScriptService
Script A … LocalScript
local player = game:GetService'Players'.LocalPlayer
local mouse = player:GetMouse()
local event = game.ReplicatedStorage.Screaming
mouse.Button1Down:connect(function()
event:FireServer()
end)
Script B … non-LocalScript
local Players = game:GetService("Players")
local event = game.ReplicatedStorage.Screaming
event.OnServerEvent:connect(function()
print("lol")
for i, player in pairs(Players:GetPlayers()) do
if player.Character:FindFirstChild("Humanoid") then
player.Character:WaitForChild("Head"):FindFirstChild("Screaming"):Play()
end
end
end)
I’m sure you will need to modify this but, this will get you in the ballpark. GL
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, message)
player.Character:FindFirstChild(“Head”):FindFirstChild(“Screaming”):Play()
print(message)
end
The code above should be in a server script in ServerScriptService.
Your local script in the text button should be written like this:
If you made it to the print you did it … now you have to figure out what is wrong with your sound.
Also there is no debounce on the mouse click … Guess I’m not really sure how you plan to use this.
As it is anyone could spam the mouse and everyone would keep screaming.
That is a raw script … it needs some love.
It may be just playing the sound over and over as fast as possible with no debounce or a check if the sound playing has finished before playing it again.
The way you had things set up it would have never worked …
You do need like Jay said to use a RemoteEvent. Both our examples show you how to do that. There is no way around it … you have to learn how to use RemoteEvents to program Roblox … Don’t fear it, it’s easy!
I know, i used remote event before but i don’t know how to face the problem of the sound not playing correctly, so i tried doing something else. I’ll try using my old RemoteEvent script as a reference but i don’t know if it’s really possible to fix the initial problem i was encountering.
ok great. You’re making it to the print so your remote is working … That means that is not the problem. Did you add a debounce to the sound call? Are you sure the sound works at all? Are you hearing any sounds?