Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

W001:Unkown Global: 'player' how can i fix this?

so I want a Button(Gui) which disables a script but the script viewer says: W001:Unkown Global: 'player' how can I fix this?

local Button = script.Parent.Button

Button.MouseButton1Click:Connect(function()
	player.PlayerGui:FindFirstChild("AudioPicker").AudioList.AudioHandler.Disabled = true
end)

and the Output says this: Button is not a valid member of TextButton "Players.123balint1.PlayerGui.Enabler.Frame.TextButton"

1 comment

0

u didn't define player

2 answers

✓ Accepted answer

You've used "player" without defining what "player" is. This will surely cause an error. Simply defining player should fix that issue.

On the issue with the Button not being a valid member of TextButton, I'm going to assume that TextButton is what you're trying to access (which in this case looks to be the parent of the LocalScript). If the object doesn't exist as a member of TextButton, then it will error. If you were trying to access a property within TextButton, there is no such thing. Removing Button from the membership expression (I apologize if my terminology is incorrect) will fix the issue.

local LocalPlayer=game:GetService("Players").LocalPlayer
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	LocalPlayer.PlayerGui:FindFirstChild("AudioPicker").AudioList.AudioHandler.Disabled = true
end)

You did not get the player properly. Use "game.Players.LocalPlayer" to get your local player. Another issue is the button not replicating fast enough in your client. In that case, use "WaitForChild("Button"), it will wait until it is replicated.

local player = game.Players.LocalPlayer
local Button = script.Parent:WaitForChild("Button")
	 
Button.MouseButton1Click:Connect(function()
player.PlayerGui:FindFirstChild("AudioPicker").AudioList.AudioHandler.Disabled = true
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.