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

I can't set attribute to a player when they join, so how do I do it?

I tried to make a script that sets attribute to a player's character once the player joins. The script is:

print("bb")
local players = game:GetService("Players")
local player = players.LocalPlayer
players.PlayerAdded:Connect(function()
	print("it works")
	local haki = player.Character:SetAttribute("Haki", false)
end)

The first print works, but the second doesn't. That probably means the function never fires. There is no error/warning outputs at all either. The script is a local script and located in StarterPlayerScripts (I've also tried moving it to StarterCharacterScripts but that didn't work)

1 answer

✓ Accepted answer

The event will not fire for the local player because the local player is loaded before the script loads; it will fire for future players that join.

Perhaps put the local script inside StarterCharacterScripts and set the attribute there; as the character is already loaded, you do not need an event.

local Character = script.Parent
local haki = Character:SetAttribute("Haki", false)

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