I’m getting it consistently in play solo, but seemingly not at all in local servers or online. I can’t tell if that’s just me getting lucky or if there’s actually some reason to it.
I have a little block of code that runs shortly after the player joins:
game.StarterGui:SetCoreGuiEnabled(“Health”, false)
game.StarterGui:SetCoreGuiEnabled(“Backpack”, false)
game:GetService(“StarterGui”):SetCore(“ResetButtonCallback”, Reset_Bindable)
with Reset_Bindable firing a server event that reloads the player’s character appearance.
EDIT: Now that I’m looking at this code again, is there even a difference between game.StarterGui and game:GetService("StarterGui")? Which one is better to use?
game:GetService'Service' finds the service by its ClassName, and creates it if it doesn’t exist. game.Service finds the service by its Name, and errors if it doesn’t exist. game:FindService'Service' finds the service by its ClassName, and returns nil if it doesn’t exist.
Always use GetService unless you have a specific reason for using FindService (e.g. NetworkServer). Never use game.Service.
I’ve always used game.Players instead of game:GetService(“Players”) tbh.
There has never EVER been a case for me where race conditions prevent accessing the service by index.
The service creates itself before scripts even run as far as I know. It’s a part of the DataModel’s construction protocol.
On top of that, they need to make it so services don’t have names that differ from their classname.
(I’m looking at you RunService, with your cheeky “Run Service” name.)
Never use indexing to get a child, period. The only exception is when the objects haven’t been exposed to the game tree or other scripts. Another exception could be pcalling it, but then you might as well be using FindFirstChild.
Might aswell rename it: SystemServerScriptService while we’re at it.
Also for those who don’t get it, I rename ServerScriptService to SService and ReplicatedStorage to RService for simplicity sake. Great practice, highly controversial, very recommended!
its even worse than my practices, and I’m the one using modulescript getfenv manipulation to inject variables into my scripts so I don’t have to rewrite them over and over.
It’s also a good idea to wrap it in a pcall so that it doesn’t kill your script in the case that they ever remove or rename the “ResetButtonCallback” trigger.
local coreCall do
local MAX_RETRIES = 8
local StarterGui = game:GetService('StarterGui')
local RunService = game:GetService('RunService')
function coreCall(method, ...)
local result = {}
for retries = 1, MAX_RETRIES do
result = {pcall(StarterGui[method], StarterGui, ...)}
if result[1] then
break
end
RunService.Stepped:Wait()
end
return unpack(result)
end
end
assert(coreCall('SetCore', 'ResetButtonCallback', false))