Hi all,
I’m looking to find the best way of basically using the CharacterAdded event on the client. Due to how the player loads before a localscript detecting if there is a new player can start, it skips over the localplayer. Here is my code on Pastebin. Problem is, it doesn’t fire the event at all. Are there any other methods, possibly better ones?
Thanks,
Crystalflxme
2 Likes
So real quick, where are you putting the local script? I’m asking because this affects when the script is loaded.
In order of when local scripts start running:
-
ReplicatedFirst
-
StarterPlayerScripts
- StarterCharacterScripts
2 Likes
My localscript is in PlayerGui.
1 Like
So any content in the StarterGui
will only load after the character spawns, and never beforehand. You can test this by turning off the CharacterAutoLoads
property in the Players
, and the Gui won’t load when you click Play.
You can fix this by putting your script in StarterPlayerScripts
and waiting for your Guis when the event fires:
game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
character:WaitForChild("HumanoidRootPart")
-- new code
local mainGameGui = game.Players.LocalPlayer.PlayerGui:WaitForChild("MainGameGuis")
local shop = mainGameGui:WaitForChild("Shop")
character.Humanoid.Changed:Connect(function()
if PointWithinArea(character.HumanoidRootPart.Position, shopArea) then
shop.Visible = true
else
shop.Visible = false
end
end)
end)
8 Likes
Tested, works great! Thank you.
1 Like