Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Attempt To Call A Nil Value?

Asked by 2 months 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 — 2mo
0
Line 19 TheNINJA152 85 — 2mo

2 answers

Log in to vote
2
Answered by
Raccoonyz 893 Donator Moderation Voter
2 months 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 — 2mo
1
Then search it up Raccoonyz 893 — 2mo
Ad
Log in to vote
0
Answered by 2 months 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 — 2mo
0
Well I assume the text is the players name right? Dynamisticality 0 — 2mo
0
Yes, it is TheNINJA152 85 — 2mo
0
Is it capitalised correctly? Dynamisticality 0 — 2mo
0
Yes, It is TheNINJA152 85 — 2mo

Answer this question