alright i might try the serverscriptservice method later, and i don’t mean to be a nuisance, but what about using repeat wait() until character
? Is it basically the same as using that arbitrary wait value?
actl nvm i just started reading the article you linked
Okay, so the localscript is giving me hell. Say that I only wanted to make the player invisible on the client, but not to anyone else. should i modify the script above to instead fire a remote event and insert a local script in starterPlayerScripts to listen for it? (p.s., why wouldn’t you put in in starterCharacterScripts)
Yup! That’s even what a Roblox Staff Member mentioned as a workaround for the use case of reliably letting the client know that CharacterAppearanceLoaded
has fired:
Here’s an example of how that could be achieved:
Codeblock #1 (Server Script)
-- Code for a Server Script placed into the ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
local function onPlayerJoin(player)
player.CharacterAppearanceLoaded:Connect(function(Character)
RemoteEvent:FireClient(player, Character)
end)
end
for _, player in Players:GetPlayers() do
task.spawn(onPlayerJoin, player)
end
Players.PlayerAdded:Connect(onPlayerJoin)
Codeblock #2 (LocalScript)
-- Code for a LocalScript placed into the StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
RemoteEvent.OnClientEvent:Connect(function(Character)
for _, v in Character:GetDescendants() do
if v:IsA("Accessory") then
v:Destroy()
elseif v:IsA("BasePart") or v:IsA("Decal") then
v.Transparency = 1
end
end
end)
If a script can be created just once and achieve the same thing rather than having it be cloned into the Character model every time they spawn, then that helps simplify things so there’s only 1 LocalScript
created per player throughout the duration they remain in the server, instead of it being re-created dozens or even hundreds of times.
As of writing this post, Character models do not have :Destroy()
called on them by default when a new one needs to spawn (it’s only set to nil
), so as far as I understand, the server memory could build up faster than it would otherwise since there are extra scripts and event connections in existence within the despawned Character models.
The LocalScript is throwing me errors. I’ve tried before and it seems that I can’t get the player’s character from starterPlayerScripts. Apologies if this is becoming a drag
Hmmm, although I’m not super sure why that would be happening, a possible solution could be to change how the Character is referenced in the LocalScript
. It could be modified a bit to access it through the LocalPlayer
rather than trying to reference the one sent through via the RemoteEvent
.
This means that the server script would only be firing an empty RemoteEvent
to the player for the sole purpose of indicating that the CharacterAppearanceLoaded
event has fired, without sending through the Character model it returns. Once the client receives that, it’ll reference the Character on its own and continue.
In the Server Script, the only thing that would need to be changed is when it calls :FireClient()
:
-- Before
RemoteEvent:FireClient(player, Character)
-- After
RemoteEvent:FireClient(player)
In the LocalScript
, how the Character is referenced in the function would be changed to access the Character
through the Player
object:
-- Revised LocalScript code for the StarterPlayerScripts
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local RemoteEvent = ReplicatedStorage.RemoteEvent
RemoteEvent.OnClientEvent:Connect(function()
local Character = player.Character or player.CharacterAdded:Wait()
for _, v in Character:GetDescendants() do
if v:IsA("Accessory") then
v:Destroy()
elseif v:IsA("BasePart") or v:IsA("Decal") then
v.Transparency = 1
end
end
end)
No worries! This has been a fun experience actually; I like the questions that you’ve been asking to learn more about the reasoning behind my suggestions. Helps to refine all of our understanding about the subject and also gives me some practice for explaining ideas that I might not have thoroughly explained before or explained that often.
Still not working. However, it partially works after you reset, only that it prints the body parts but doesn’t make them invisible. Curiously, it’s not picking up any accessories. I’ve disabled every script except for the server script and this one and nothing changed.
i’m starting to think roblox studio has something against me
Honestly, I am super stumped now lol. With all of these different setups, whether it’s just a LocalScript
, just a server Script
, or a mixture of the two, I haven’t been able to replicate the broken behavior (it’s worked every time during my own testing).
What happens if you try testing it in a live game? Maybe it’s different in Roblox Studio for some reason but works as intended in the published version of the game.
I’ve exhausted what seems like all the options without adding an arbitrary delay back into the code, so hopefully it just happens to work properly in a live server?
maybe you could try publishing a place of your own and see if the script works
Oh yeah have a go at it and see if you turn invisible
The game is set to private so it isn’t letting me join.
If I join afterwards and my Character goes invisible and your Character model doesn’t, that will be even more unbelievably confusing haha.
I had just gone into Roblox Studio and added your Character model into the Workspace as both R6 and R15 RigTypes and tested a slightly modified version of the code to see if it could make your Character model fully invisible right away or if it encountered any issues and it made both invisible so I’m still super confused lol.
my bad gonna make it public real quick
alright just made it public
I am so confused right now; the same thing happened as in the screenshot you posted earlier. The same things are printing out in the Developer Console (excluding all Accessories), and my Character wasn’t turned invisible.
Not sure what’s working differently there when I wasn’t able to replicate that in any of my own places / experiences that I tested the code in.
you mean you played my game and the same thing that happened to me happened to you?
btw do you want to just check the actual place out on studio? i could post it here
I could, but I prefer to not download files. If you could post it as a separate uncopylocked place on Roblox, I could edit through there to check (sorry for the inconvenience)
aight just made it uncopylocked hopefully