I have sounds playing with 0 pitch in the PlayerGUI so this script below which is in a GUI button, when pressed it should be changing the Pitch of the sound to 1, but for some reason it's not working.
local plr = script.Parent.Parent.Parent.Parent function onClick(mouse) player.PlayerGui.Music.Pitch = 1 end script.Parent.MouseButton1Click:connect(onClick)
In the output I'm getting:
22:29:31.728 - Players.Player1.PlayerGui.ScreenGui.TextButton.script:4: attempt to index global 'player' (a nil value)
22:29:31.732 - Stack Begin
22:29:31.733 - Script 'Players.Player1.PlayerGui.ScreenGui.TextButton.script', Line 4
22:29:31.734 - Stack End
On line 1. You made plr to be the player value. So change line 4 to plr.
local plr = script.Parent.Parent.Parent.Parent function onClick(mouse) plr.PlayerGui.Music.Pitch = 1 end script.Parent.MouseButton1Click:connect(onClick)
local plr = script.Parent.Parent.Parent.Parent function onClick(mouse) plr.PlayerGui.Music.Pitch = 1 --plr is a variable for I'm guessing the player. Also, is music a Gui or sound? end script.Parent.MouseButton1Click:connect(onClick)
If it's a local script you can do Local Player
local plr = game.Players.LocalPlayer --Notice how the LocalPlayer is in the players. Local player is better than writing a bunch of "Parents." function onClick(mouse) plr.PlayerGui.Music.Pitch = 1 --plr is a variable for I'm guessing the player. end script.Parent.MouseButton1Click:connect(onClick)
Also, there is a shortcut to making scripts with functions in them that are connected to events.
local plr = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect(function (mouse) --Make it look something like this. Notice how I compleatly got rid of the "onClick" because it's useless now. plr.PlayerGui.Music.Pitch = 1 --plr is a variable for I'm guessing the player. end)