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

Changing Value in Filtering Enabled but I got this error Attemp to index field ' ' (a nil value)?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local ServerScriptService = game:GetService("ServerScriptService")
local RPG Engine = ServerScriptService:WaitForChild("RPG Engine")

local RemoteEvent = Instance.new("Folder", ReplicatedStorage)
RemoteEvent.Name = "CharacterCreationRemote"

local HairChangerRightEvent = Instance.new("RemoteEvent", RemoteEvent)
HairChangerRightEvent.Name = "HairChangerRight"

local HairChangerLeftEvent = Instance.new("RemoteEvent", RemoteEvent)
HairChangerLeftEvent.Name = "HairChangerLeft"

-- Functions --

local function HairChangerRight(player)
    (player.Name).Cosmetics.HairStyle.Value = (player.Name).Cosmetics.HairStyle.Value + 1
    
    if (player.Name).Cosmetics.HairStyle.Value > 10 then
	  (player.Name).Cosmetics.HairStyle.Value = 0
	end
end

local function HairChangerLeft(player)
    (player.Name).Cosmetics.HairStyle.Value = (player.Name).Cosmetics.HairStyle.Value + 1

    if (player.Name).Cosmetics.HairStyle.Value > 0 then
	   (player.Name).Cosmetics.HairStyle.Value = 10
	end
end

-- Function Callings --

HairChangerRightEvent.OnServerEvent:Connect(HairChangerRight)
HairChangerLeftEvent.OnServerEvent:Connect(HairChangerLeft)

The Folder is in ServerStorage holding a folder with the player name and 6 subfolders containing values. So Comestics is a subfolder.

1 answer

Do your RemoteEvents fire with the player? If not, then your functions will think player is nil, causing an error to happen.

To fix this, simply do this to whatever is firing the events :

RemoteEvent:FireServer(Player) - - If firing FROM a localscript

RemoteEvent:FireClient(Player) - - If firing FROM a script

Also make sure you specify what the player is exactly. Simply putting “Player” isn’t going to work. :P

2 comments

0

It fires with the player it just says Attempt to index field 'Cosmetics' (a nil value)

0

Oh, it seems your code is directly trying to find “Cosmetics” IN the player. Make sure you specify where the player and cosmetics are. Like “game.Workspace(player.Name).Cosmetics”.

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