Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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"

0
u didn't define player 0fficialHen 5 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
Ad
Log in to vote
0
Answered by
Cirillix 110
3 years ago
Edited 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

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)

Answer this question