so I have a simple character selection script here, for when you press a button (from top bar plus) it will fire a Remote Event (CharacterSelected) that will go to this script in StarterCharacterScripts here:
local RepStore = game:GetService("ReplicatedStorage")
local GameCharacter = RepStore.Characters.PlaceholderCharacter
local AssetsFolder = GameCharacter.Assets
local RemotesFolder = GameCharacter.Remotes
local Players = game:GetService("Players")
local myCharacter = script.Parent
local myPlayer = Players:GetPlayerFromCharacter(myCharacter)
RemotesFolder.CharacterSelected.OnServerEvent:Connect(function(remotePlayer)
if remotePlayer ~= myPlayer then
return end
RemotesFolder.CharacterSelected:FireClient()
end)
which it will then fire again, only its “FireClient()” now because its in a server script. I would fire client directly when you press the button other then this weird way, but the script is local so i have to do this. There will be a script in StarterGui that will recieve the FireClient() but whenever i run this, the script gets this weird error: Argument 1 missing or nil
I have no idea what this means, if anyone could please help or revamp my scripts entirely, that would be huge.
Also the way I store characters into the user sucks. Literally just a string value that you get when you spawn so changing it wouldn’t be permanent. If people could help make one that saves even when you leave or reset it would be awesome! thanks.
You provided the wrong script, you literally told us the error occurs once it reaches the client, so you should’ve provided the client script.
Also if the only reason you have a remote is to from the client, redirect back to the client, use a bindable event instead.
Also you could store the string value as an attribute on the player and whenever the player’s character is added load your character that is referenced in the stringvalue. This way when you reset it doesn’t go away. As for saving, use DataStoreService
You need to pass which player you’re firing to. That’s why it’s screaming the first argument is missing is because the player you’re firing to is nil
The issue is that you aren’t passing the player argument in the FireClient method. Do remember that FireClient requires a player to be used as the first argument. If you want to send the event for all players then use FireAllClients.
--you add attributes just using SetAttribute
YourPlayer:SetAttribute("Character", "name of char")
--they work on any instance
As for the datastore you want to get a datastore for the player, when the player joins you load the value from datastore, when they leave or the game closes down you save it, and maybe you auto save every once in a while.
--simplified example that shouldn't actually be used
local players = game:GetService("Players")
local datastores = game:GetService("DataStoreService")
local yourstore = datastores:GetDataStore("yourname")
local function save(plr: Player)
yourstore:SetAsync("Character"..plr.UserId, plr:GetAttribute("Character"))
end
players.PlayerAdded:Connect(function(plr)
local success, data = pcall(function()
return yourstore:GetAsync("Character"..plr.UserId)
end)
if not success then
plr:Kick("failed to load data")
else
plr:SetAttribute("Character", data)
end
end)
players.PlayerRemoving:Connect(save)
game:BindToClose(function()
for _, p in ipairs(players:GetPlayers()) do
save(p)
end
end)
This is a simplified example that does the absolute minimum, normally you 'd add retrying mechanisms, cacheing, session locking, and you might name or sort things differently, but that is outside of the scope of a single devforum comment, I suggest you read the documentation of datastoreservice:
Also I’m typing this on my phone and I just wrote this off the top of my head so if I got some of the api method names wrong then sorry, but the structure should be the same anyway.
Also what @sonic_848 said is the answer so you should mark it as the solution. I thought it said FireAllClientsđź’€
Datastoreservice can only be accessed on the server, it doesn’t matter where you put it as long as it’s on the server. I suggest ServerScriptService though.
Don’t copy the example above, as it is missing a lot of key features, it is just there to show you the bare minimum for it to work. But you should write your own.