So i made this script for when a player join the game, it creates a “IntValue” inside player for save his shirt/pants id
but its not working, and dont give any error on console
can someone help?
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local shirtid = Players:FindFirstChildOfClass("anynamecuzdontexist")
local pantsid = Players:FindFirstChildOfClass("anynamecuzdontexist")
if not shirtid then
shirtid = Instance.new("IntValue", Players)
shirtid.Name = "PlayerOldShirtId"
shirtid.Value = Players.Shirt.ShirtTemplate
end
if not pantsid then
shirtid = Instance.new("IntValue", Players)
shirtid.Name = "PlayerOldPantsId"
shirtid.Value = Players.Pants.PantsTemplate
end
end)
This is a LocalScript On StarterPlayer > StarterPlayerScripts
is false, then the script creates a IntValue inside player, but the script is not creating a IntValue inside, and not giving any error on console
All i need is create a IntValue on player with his ShirtTemplate/PantsTemplate
Not sure why you are doing it like this but you could add this maybe;
local shirtid = Players:FindFirstChildOfClass("anynamecuzdontexist") or false
The reason I say why are you doing it like this is because you already know it doesn’t exist so why not just create the Values. Oh basically what @EmbatTheHybrid said, sorry I didn’t see that reply.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local shirtid = Instance.new("StringValue") --ShirtTemplate returns the url, not the id
shirtid.Name = "PlayerOldShirtId"
shirtid.Parent = player
local pantsid = Instance.new("StringValue") --PantsTemplate returns the url, not the id
pantsid.Name = "PlayerOldPantsId"
pantsid.Parent = player
player.CharacterAppearanceLoaded:Connect(function(char)
shirtid.Value = char.Shirt.ShirtTemplate
pantsid.Value = char.Pants.PantsTemplate
end)
end)
It should do what you wanted, for each time a player joins, add 2 StringValues in their instance, and when their Character Fully loads, just store the Templates in there
Because this is in a localscript, it wont work for your player but for otehrs, It’s best you put this in a serverscript instead. And this wont work the first time the character fully loads, but the other times it will
Here you’re referencing the service rather than the player. So you’re adding this int value to the service. To make it add it to the player, make sure to make the parent be “player” instead of “Players”
In addition to this, if you’re doing this on the client, PlayerAdded wouldn’t work well for this scenario. Consider putting it on the server instead. If you do put it on the server, also make sure to remember that players can join before PlayerAdded is fired so bind PlayerAdded to a function and also make that function be called for any player already inside of the game
Also, you’re doing this to the player rather than character so you cant do “player.Shirt.ShirtTemplate” since that isn’t the character (player.Character would be the character)