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

attempt to index nil with 'PlayerTools'?

Asked by
Zelt3q 31
3 years ago

Hello. I have a problem with my shop Gui.

local price = script.Parent.Price
local price2 = script.Parent.Parent.Info.Price
local price3 = script.Parent.Parent.Info.ItemPrice
local name = script.Parent.ItemName
local name2 = script.Parent.Parent.Info.ItemName
local name3 = script.Parent.Parent.Info.ItemName1
local image = script.Parent.ItemImage
local image2 = script.Parent.Parent.Info.ItemImage

script.Parent.MouseButton1Click:Connect(function(player)
    print("Hey")

        price2.Value = price.Value
        price3.Text = price.Value
        name2.Text = name.Value
        name3.Value = name.Value
        image2.Image = image.Value
        if player.PlayerTools:FindFirstChild(player.PlayerGui.Shop.ShopFrame.Info.ItemName.Text) then
            print("Hola")
            player.PlayerGui.Shop.ShopFrame.Info.Buy.Text = "Equip"



        end
end)

The Error is: Players.Zelt3q.PlayerGui.Shop.ShopFrame.Item1.Script:18: attempt to index nil with 'PlayerTools'

Btw I have a folder named PlayerTools

0
Define the localplayer JesseSong 3916 — 3y

2 answers

Log in to vote
1
Answered by
TopBagon 109
3 years ago

I'm pretty sure this is in a LocalScript (otherwise it wouldn't work), You're trying to get a player parameter but MouseButton1Click won't give you that (MouseClick from the click detector does that) because you can just get the local player since this is a LocalScript, add this on top of your function

local player = game:GetService("Players").LocalPlayer

Let me know if this works or not. Cheers

0
No it is in a normal script, and yes it do work. I'm having a problem making a player variable in the normal script. Because when I do local script the shop gets broken Zelt3q 31 — 3y
0
I don't know how you made it to work (if it works server-sided as well) but that's not a good idea considering security. Try to rewrite it in LocalScript and use remote events if you can't get them to work TopBagon 109 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Since you want it to be a serverside script,

game.Players.LocalPlayer

is not going to work.

I would just parent until it reaches the player (the player is a child of game.Players)

For example, there is a gui, a frame, a script, and a textbutton. To get the player, I would do

script.Parent.Parent.Parent.Parent.Parent

To explain it more:

script - The script (Its Parent is Text Button)

Parent - Text Button (Its Parent is Frame)

Parent - Frame (Its Parent is Gui)

Parent - Gui (Its Parent is PlayerGui)

Parent - PlayerGui which is where all the guis are stored (for each player) (Its Parent is the Player from game.Players)

Answer this question