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

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

Asked by 1 year ago

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

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

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)
Ad

Answer this question