Attribute able to be created outside the function but not inside the function

  1. What do you want to achieve?
    Just create a new attribute when the player joins

  2. What is the issue?
    it just doesnt work at all idk why but if i put it out of the function it just works??? It works but i think it might be harder code like this later on

  3. What solutions have you tried so far?
    Couldnt find anything talking about it

not sure why is this possibly an idiot

also the script is a local script

This script wont create it

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr:SetAttribute("Sanity", 100)
end)

this WILL

local player = game:GetService("Players").LocalPlayer

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr:SetAttribute("Sanity", 100)
end)

player:SetAttribute("Sanity", 100)

Are you testing this in Studio, or on the website? Studio can have issues with .PlayerAdded, try publishing it and trying on the website

I tried it on the website, didnt work at all

actaully the script is a local script forgot to mention that

Players.PlayerAdded doesnt fire at client

I see no problem with or you can creatr it in server

1 Like

Use that in a server script or don’t use the PlayerAdded Event.

1 Like

Like other people have said, do this on the server, not the client.

The reason this doesn’t work is that the code loads after the player connects to the server. So the PlayerAdded event triggeren when the client joins, can never be received by the client itself.

3 Likes

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