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

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

Asked by 6 years ago
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

Log in to vote
0
Answered by 6 years ago

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

0
It fires with the player it just says Attempt to index field 'Cosmetics' (a nil value) Entirely76 2 — 6y
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”. User#20279 0 — 6y
Ad

Answer this question