Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

A better way of doing this?

Asked by 9 years ago

I've been working on an RPG map and I'm stuck... What my aim here is when a player joins, they spawn right above the brick (The onTouch one), and when they hit it the script happens so I can have a custom GUI with a character selection etc. What I'm after is how can I make this more efficient and so it happens without the player touching the brick?

01function onTouch(hit)
02        if hit.Name == "Left Leg" then
03                for _,v in pairs(hit.Parent:GetChildren()) do                 
04 
05                        if v:IsA("CharacterMesh") then
06                                v:Remove()
07                        end
08 
09                        if v:IsA("Shirt") then
10                                v:Remove()
11                        end
12 
13                        if v:IsA("T-Shirt") then
14                                v:Remove()
15                        end
View all 36 lines...

Thanks, jakei181

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

You can do things when the character spawns by using the CharacterAppearanceLoaded event, which is just like CharacterAdded, but it waits for the assets to load.

01game.Players.PlayerAdded:connect(function(player)
02    player.CharacterAppearanceLoaded:connect(function(character)
03        for _,v in pairs(character:GetChildren())do
04            if v:IsA("CharacterAppearance")then
05                v:Destroy()
06            end
07            game.ServerStorage.HeadMesh:clone().Parent=character.Head
08        end
09    end)
10end)

An even better way to not have to deal with character assets is to set Player.CanLoadCharacterAppearance to false when they join.

edit:

Player.CharacterAdded is an event of the Player class. It is fired when a player respawns or when Player:LoadCharacter() is called, and it provides the new character as an argument.

1game.Players.PlayerAdded:connect(function(player)
2    player.CharacterAdded:connect(functon(char)
3        print(char.Name.."'s character spawned")
4    end)
5end)

Player.CharacterAppearanceLoaded does the same thing, but it doesn't fire immediately when the character spawns. Instead, it waits for the hats, packages, etc. to load into the character object. If you were to try to access (or remove) these objects before they loaded, they would not be there yet.

0
Thanks! May you show me how to do Player.CanLoadCharacterAppearance? jakei181 60 — 9y
Ad

Answer this question