I know I already asked a question similar to this, and the answer was for me to create a remote event. I did, but I have run into another problem.
What I'm trying to do is make a button that, when you click it, gives you the ability to make a noise by pressing "1" on the keyboard.
I have a Local Script inside the GUI with the button that gives this power to the player.
function onClick()
local action = game:GetService("ReplicatedStorage"):WaitForChild("MakeSound")
action:FireServer()
end
script.Parent.MouseButton1Click:Connect(onClick)
Then, I have a remote event called "MakeSound" in the ReplicatedStorage.
Finally, I have a script in the ServerScriptService that looks like this:
local action = game:GetService("ReplicatedStorage"):WaitForChild("MakeSound")
player = game.Players.LocalPlayer
char = player.Character
humn = char.Humanoid
mouse = game.Players.LocalPlayer:GetMouse()
function KeyD(key)
key = key:lower()
if key =="1" then
local sound = Instance.new("Sound")
sound.Volume = 1
sound.SoundId = "rbxassetid://725011552"
sound.Parent = char.Head
sound:Play()
wait(3)
sound:Destroy()
end
end
mouse.KeyDown:connect(KeyD)
My theory was that after the player clicks on the GUI, it allows for them to start making this sound by pressing 1, but the output tells me "attempt to index global 'player' (a nil value)" for Line 2.
As a beginner, I have no idea where to start problem solving. Any solutions? Please be descriptive!

3 comments
Thank you so much, this was incredibly helpful. I wish I could upvote this! Thanks for being detailed and explaining everything. I am trying to learn as much as I can. However, when I followed the advice, I came across another error. "attempt to index global 'mouse' (a nil value)" for line 24. Shouldn't this not happen since the variable is defined above? Thanks for all your help
Okay, I got it to work, but only on Studio, not when i play it in game. It fires a remote event so I'm not sure why its not working in game.
Turns out it ended up working without a remote event at all! I took out the remote event and FireServer, and put the sound inside of a part on the player, and it works online and others can hear it. Thanks!