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

Help! attempt to index nil with 'Data'? [closed]

Asked by 4 years ago
Edited 4 years ago

My script dont work because it attempt to index nil with Data? here script

local debounce = false
local summon = false
local UIS = game:GetService("UserInputService")


UIS.InputBegan:Connect(function(Input,IsTyping)
    if IsTyping then return end

    if Input.KeyCode ==  Enum.KeyCode.Q and Player.Data.HasStand.Value == true then
        if summon == false then

            summon = true
            print("summoned the stand")
            game.ReplicatedStorage.Jojo:WaitForChild("SummonStand"):FireServer()
            script.Parent:WaitForChild("Equip").Value = true
        elseif summon == true then
            print("destroyed the stand")
            summon = false
            game.ReplicatedStorage.Jojo:WaitForChild("DestroyStand"):FireServer()
            script.Parent:WaitForChild("Equip").Value = true
        end
    end
end)


if Input.KeyCode == Enum.KeyCode.Q and Player.Data.HasStand.Value == true then

that is the line with the error i think

0
Do you ever define 'Player' ? cowsoncows 951 — 4y
0
Yes superplayer1453 -4 — 4y
0
but it still dont work and i try with 'Players' superplayer1453 -4 — 4y
0
Can you edit your question with the code where Player is defined? Your error means `Player` is nil, so something must be up with that part. cowsoncows 951 — 4y
View all comments (3 more)
0
ok superplayer1453 -4 — 4y
0
I still don't see it defined anywhere. When I say 'define' it means where you initiate the variable, somewhere should say something like: local Player = game.Players.LocalPlayer cowsoncows 951 — 4y
0
o superplayer1453 -4 — 4y

Closed as Not Constructive by JesseSong

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
game.Player.PlayerAddded:Connect(function(player)

    local data = Instance.new("Folder")
    data.Name = "Data"
    data.Parent = player


    local hasStand = Instance.new("BoolValue")
    hasStand.Name = "HasStand"
    hasStand.Value = false
    hasStand.Parent = data

    local standName = Instance.new("StringValue")
    standName.Name = "StandName"
    standName.Parent = data

end)

There the Data in server script service

When i press q it put the error there it say Players.superplayer1453.Backpack.Summoning:9: attempt to index nil with 'Data'

0
What kind of answer is this? JesseSong 3916 — 4y
Ad