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

attempt to index nil with 'UserId' ?

Asked by 4 years ago
Edited 4 years ago

I'm trying to script a badge that awards the player when they typed the correct password, but it keeps showing up with the 'attempt to index nil with 'UserId' ' error. How can I fix this?

I used a local script in a surface gui:

script.Parent.MouseButton1Click:Connect(function() if script.Parent.Parent.TextBox.Text == "krxtenaa" then script.Parent.Parent.Parent.Desktop.Visible = true script.Parent.Parent.TextBox.Text = "" local BadgeService = game:GetService("BadgeService") BadgeService:AwardBadge(player.UserId, 2124658487) elseif script.Parent.Parent.TextBox.Text == "26/4/2019" then script.Parent.Parent.Parent.VoiceMemo.TextButton.Visible = true script.Parent.TextScaled = true script.Parent.Text = "Secret Voice Memo Unlocked." wait(2) script.Parent.TextScaled = false script.Parent.Text = "Enter" script.Parent.Parent.TextBox.Text = "" else script.Parent.Text = "Incorrect!" wait(2) script.Parent.Text = "Enter" script.Parent.Parent.TextBox.Text = "" end end)

0
First of all, when you are showing your code use the Lua button instead of the code block button. Secondly, as far as your code goes you did not define player. Simply typing player isn't enough. In a local script you can get the player by doing---- local player = Game.Players.LocalPlayer WizyTheNinja 834 — 4y

Answer this question