Ad
Log in to vote
1

Attempt to index nil with number, can anyone help me?

Asked by 6 days ago
Edited 6 days ago

Can anyone please help me? It's for a character creation script. Error happens at line 48

local plr = script.Parent.Parent.Parent.Parent.Parent

repeat wait() until plr:FindFirstChild("PlayerGui")


local Datastore = game:GetService("DataStoreService"):GetDataStore("V4Slot1")
local PData = Datastore:GetAsync(plr.UserId)

if PData ~= nil and PData[6] == true then
    script.Parent.Text = PData[7]
end

if plr.PlayerData.LoadedSlot.Value == "Slot1" or plr.PlayerData.LoadedSlot.Value == "Slot2" or plr.PlayerData.LoadedSlot.Value == "Slot3" then
    script.Parent.Parent.Visible = false
end

script.Parent.Delete.MouseButton1Click:Connect(function()
    PData[6] = false
    script.Parent.Text = "+"
end)

script.Parent.MouseButton1Click:Connect(function()
    if script.Parent.Text == "+" then
        script.Parent.Parent.Parent.Slot.Value = "1"
        script.Parent.Parent.Parent.CharacterSlots:TweenPosition(
            UDim2.new(-0.31, 0,0.364, 0),   
            Enum.EasingDirection.Out,
            Enum.EasingStyle.Back,
            0.5,
            true
        )
        local TweenService = game:GetService("TweenService")
        local time = 1
        local tween2 = TweenService:Create(script.Parent.Parent.Parent.Screen, TweenInfo.new(time), {BackgroundTransparency = 0})
        tween2:Play()
        tween2.Completed:Connect(function()
            script.Parent.Parent.Parent.CharacterSlots.Visible = false
            wait(2.1)
            script.Start.Value = true
            local TweenService = game:GetService("TweenService")
            local time = 1
            local tween2 = TweenService:Create(script.Parent.Parent.Parent.Screen, TweenInfo.new(time), {BackgroundTransparency = 1})
            tween2:Play()
            script.Parent.Parent.Parent.Start.Visible = true
        end)
    else
        if plr.PlayerData.LoadedSlot.Value ~= "Slot1" or plr.PlayerData.LoadedSlot.Value ~= "Slot2" then
            plr.PlayerData.Shirt.Value = PData[1]
            plr.PlayerData.Pants.Value = PData[2]
            plr.PlayerData.Hair.Value = PData[3]
            plr.PlayerData.Weight.Value = PData[4]
            plr.PlayerData.Height.Value = PData[5]
            plr.PlayerData.PName.Value = PData[7]
            plr.PlayerData.Gender.Value = PData[8]
            plr.PlayerData.FacialHair.Value = PData[9]
            plr.PlayerData.Age.Value = PData[10]
            plr.PlayerData.SkinR.Value = PData[11]
            plr.PlayerData.SkinG.Value = PData[12]
            plr.PlayerData.SkinB.Value = PData[13]
            plr.PlayerData.Time.Value = PData[14]
            plr.PlayerData.Color.Value = PData[15]
            plr.PlayerData.Cash.Value = PData[16]
            plr.PlayerData.Hat.Value = PData[17]
            plr.PlayerData.LoadedSlot.Value = "Slot1"
            plr.PlayerData.HasData.Value = true
            plr:LoadCharacter()
            game.ReplicatedStorage.Remotes.ToClient:FireClient(plr, "ResetCam")
        end
    end
end)

EDIT

As I found out, It was cause of the TextButton, not the script.

1 answer

Log in to vote
0
Answered by
Vong25 297 Moderation Voter Administrator Community Moderator Super Administrator
6 days ago

PData is nil. This could be due to the player not having any data under their id.

0
PData is created after the player makes a character. hndcwffs 5 — 6d
Ad

Answer this question