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

Attempt To Call A Nil Value?

Asked by 3 years ago

I'm trying to make a ban button and it shows me this error, can anyone help me?

Here's my script

local banDataStore = game:GetService("DataStoreService"):GetDataStore("banDataStore")
local Frame = script.Parent.Parent





script.Parent.MouseButton1Click:Connect(function()
    local Player = Frame.Username.Text
    local PlayerUID = Player.UserId
    local success, errorMessage = pcall(function()
        banDataStore:SetAsync(PlayerUID, true)
    end)

    if not success then
        print("L")
    end

    Player:Kick("You've been banned from this game!")


end)
0
What line is the error at? Dynamisticality 0 — 3y
0
Line 19 TheNINJA152 85 — 3y

2 answers

Log in to vote
3
Answered by
Raccoonyz 1092 Donator Moderation Voter
3 years ago

I assume that the Frame.Username is a TextBox, which would probably be causing the error.

You can't get the content of a TextBox in a server script, so you'd have to use RemoteEvents.

0
The problem is that I don't know how to TheNINJA152 85 — 3y
2
Then search it up Raccoonyz 1092 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You are doing Player = Frame.Username.Text which is a string value, if you'd like to get the actual player you'd do

local Player = game.Players[Frame.Username.Text]

and it should work

0
Now it says " is not a valid member of Players" without the username TheNINJA152 85 — 3y
0
Well I assume the text is the players name right? Dynamisticality 0 — 3y
0
Yes, it is TheNINJA152 85 — 3y
0
Is it capitalised correctly? Dynamisticality 0 — 3y
0
Yes, It is TheNINJA152 85 — 3y

Answer this question