Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index nil with 'PlayerTools'?

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

1 comment

0

Define the localplayer

2 answers

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

2 comments

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

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.