hi so i rlly need help. i have a local script which makes a button only appear on my screen and none of the other player’s screens. when pressed, it makes an event happen where the lights go out and sounds play and stuff WHICH WORKS GREAT but when playing with other random people, i realized that the sound and stuff are only playing for me. im rlly confused on how would i make it so that only the button part happens for me but the effects happen for everyone
local bright = game.Lighting.bright
local shutoff = script.Parent.Sound
local scare = script.Parent.Sound2
local areas = game.StarterPlayer.StarterPlayerScripts.Regions.Sound
local on = script.Parent.Sound3
local amb = script.Parent.Sound4
local player = game.Players.LocalPlayer
if player.Name == "alexeons" then
script.Parent.Parent.Enabled = true
end
game.StarterGui.ScreenGui.TextButton.MouseButton1Click:Connect(function()
shutoff:Play()
amb:Play()
black.Enabled = true
bright.Enabled = true
wait(6)
scare:Play()
wait(9)
amb:Stop()
black.Enabled = false
bright.Enabled = false
on:Play()
end)```
Because it is a local script thus the sound is not playing on the server and only the client.
To make the sound play on the server fire a remote event and pick the call up from the server and play the sound from there.
Remote Events basically provides a way to communicate between the Client(Players) and the server.
There are some things the server cannot detect for example user input so local scripts are used in that case.
In this case, you want so that when you press the button everything occurs on the server.
You could have used server script but you want to check if the player is someone specific , in this case you have to use remote event.
To do the following add a remote event in replicated storage as it is replicated to both server and client
> LOCAL SCRIPT
>
> local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent") : Got the remote event
>
> local player = game.Players.LocalPlayer
>
> if player.Name == "alexeons" then
> script.Parent.Disabled = false
> end
>
> game.StarterGui.ScreenGui.TextButton.MouseButton1Click:Connect(function()
> remoteEvent:FireServer()
> end)
>
> SERVER SCRIPT
>
> local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent") : Got the remote event
> local bright = game.Lighting.bright
> local shutoff = script.Parent.Sound
> local scare = script.Parent.Sound2
> local areas = game.StarterPlayer.StarterPlayerScripts.Regions.Sound
> local on = script.Parent.Sound3
> local amb = script.Parent.Sound4
>
> remoteEvent.OnServerEvent:Connect(function()
> shutoff:Play()
> amb:Play()
> black.Enabled = true
> bright.Enabled = true
> wait(6)
> scare:Play()
> wait(9)
> amb:Stop()
> black.Enabled = false
> bright.Enabled = false
> end)
script is in serverscriptstorage and local script is in starter gui. where should i add the print statements? also i changed the vairables around a bit in the server script and put the audios in workspace, is that okay?
local bright = game.Lighting.bright
local shutoff = game.workspace.Sound
local scare = game.workspace.Sound2
local areas = game.StarterPlayer.StarterPlayerScripts.Regions.Sound
local on = game.workspace.Sound3
local amb = game.workspace.Sound4
local Remote = game:GetService("ReplicatedStorage").Remote
Remote.OnServerEvent:Connect(function(player) -- Listens out for event
print(player.Name.." triggered the event to run.")
shutoff:Play()
amb:Play()
black.Enabled = true
bright.Enabled = true
wait(6)
scare:Play()
wait(9)
amb:Stop()
black.Enabled = false
bright.Enabled = false
on:Play()
end)```
i added a print statement here, which did not work
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("Remote")
local player = game.Players.LocalPlayer
if player.Name == "alexeons" then
script.Parent.Parent.Enabled = true
end
game.StarterGui.ScreenGui.TextButton.MouseButton1Click:Connect(function()
print("testing")
remote:FireServer()
end)
i have the script inside the text button, which is inside the gui so i did script.parent.parent.enabled (which is off) and then that turns it on for me