Script Not Getting Attributes

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I would like to be able to access to the values of the attributes.

  2. What is the issue? Include screenshots / videos if possible!
    The following script is a simple script, not module, not local.
    It returns the right variable format, but what’s in the value isn’t right.

	local Folder = game.Workspace.Date.Giocatori:FindFirstChild("=" ..player.Name)
	local Nome = Folder:GetAttribute("Nome") --string, can't find value
	local Color = Folder:GetAttribute("Colore") --Color3, can't find value
	local Intro = Folder:GetAttribute("Intro") --bool, can't find value
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    tried searching around, sadly found nothing
1 Like

Are you changing the attributes on a server or local script? how are you changing theses attributes exactly?

@mniao
The attributes value is getting changed in a module script.
The code where I cange the value is the following:

local ChangeNameColor = {}

function ChangeNameColor.ChangeName(player, name)
	
	local Tag = game.Workspace.Date.Giocatori:FindFirstChild("=" .. player.Name)

	Tag:SetAttribute("Nome",name)

end

function ChangeNameColor.ChangeColor(player, Color)

	local Tag = game.Workspace.Date.Giocatori:FindFirstChild("=" .. player.Name)
	
	Tag:SetAttribute("Colore",Color)
	
end

return ChangeNameColor

The script which i’m asking help with is a script where i save the Attributes, but the script is having problems getting the Attributes values.

You should do a print like this to check if it’s actually running the code and setting it to the value that it’s supposed to be

	local Tag = game.Workspace.Date.Giocatori:FindFirstChild("=" .. player.Name)

	Tag:SetAttribute("Nome",name)

    print(Tag, name, player) --Does this print? is it printing the correct values if it is printing?

it sets the right values cause i can see them from the object in the workspace. They are not begin taken by the script that should save them tho.

Alright, then maybe it’s not getting the correct instance somehow?

local Folder = game.Workspace.Date.Giocatori:FindFirstChild("=" ..player.Name)
print(Folder:GetFullName()) --is it the correct instance?
local Nome = Folder:GetAttribute("Nome") --string, can't find value
local Color = Folder:GetAttribute("Colore") --Color3, can't find value
local Intro = Folder:GetAttribute("Intro") --bool, can't find value

Also i’m sorry but i don’t understand exactly what you mean by this

it’s gets the correct instance. I’m going crazy over this script :face_exhaling:

I made a test script using your code and it seems to work, here’s the code i used.

local players = game:GetService("Players")

local ChangeNameColor = {}

function ChangeNameColor.ChangeName(player, name)

	local Tag = game.Workspace.Date.Giocatori:FindFirstChild("=" .. player.Name)

	Tag:SetAttribute("Nome",name)

end

function ChangeNameColor.ChangeColor(player, Color)

	local Tag = game.Workspace.Date.Giocatori:FindFirstChild("=" .. player.Name)

	Tag:SetAttribute("Colore",Color)
	
end

players.PlayerAdded:Connect(function(player)
	local testFolder = Instance.new("Folder")
	testFolder.Name = "="..player.Name
	testFolder.Parent = workspace.Date.Giocatori
	
	task.wait(10)
	ChangeNameColor.ChangeColor(player, Color3.new(1, 0, 0))
	ChangeNameColor.ChangeName(player, "name wow")
	
	task.wait(10)
	local Folder = game.Workspace.Date.Giocatori:FindFirstChild("=" ..player.Name)
	local Color = Folder:GetAttribute("Colore")
	local Nome = Folder:GetAttribute("Nome")
	
	print(Color) --prints correct value
	print(Nome) --also prints correct value
end)

image

Are you sure you’re not setting the attributes on a client script?

How do i see if I set the attributes on a client script?

Are you using a LocalScript? text

to set the attributes value i use a module script

To get the attributes and save them a normal script, not local

Please keep in mind that ModuleScripts only run when they are required using require().

yeah. That ModuleScript start running thanks to a local script

Bingo, you are basically setting the attributes on a localscript as when you require() it’s basically running the module code on that script, please set the attributes on the server instead.

2 Likes

so the local script that starts the module is the problem. Thank you a lot, after years we found out xD

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.