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 a nil value?

I have a handle, inside a tool, and once the tool equips, the mesh inside the tool will change it's texture. However, only the client can see the mesh's texture change, not the rest of the server. I therefore created a remote event which contacts the server, and the server would then change the texture of the mesh, so that all clients can see the texture change. I have set up a server script to do this task when it recieves the RemoteEvent, containing the player's name, from the client, but whenever I run the script I get the following error on line 2: 'Attempt to index a nil value.' The tool is called 'Excel Energy', and the RemoteEvent is called 'ExcelEnergyOpenCan'.

local function eventFired(player)
	player.Backpack:FindFirstChild("Excel Energy").Handle.Mesh.TextureId = "rbxassetid://2175878581"		
end

game:GetService("ReplicatedStorage").Events.ExcelEnergyOpenCan.OnServerEvent:Connect(eventFired)

5 comments

1

there might be no "Backpack" inside the player, no "Excel Energy" inside the Backpack or no handle or mesh inside excel energy.

0

Is there a way to check if each individual object exists? To find out which one is nil? You could try something like this: local function eventfFired(player) player:FindFirstChild("backpack") print ("Backpack exists") player.backpack:FindFirstChild.... ect

0

Do :WaitForChild()

0

no

0

@radusavin366 What do you mean no Backpack inside the player? Every player spawns with a backpack..

1 answer

Go into studio and test it. Check inside the player folder if there is a Folder called Backpack, Then if the Weapon is inside, then the Handle and then the Mesh. If they are all there in the proper order use a WaitForChild() for the Backpack, Weapon and Handle and that should fix it.

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