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

How would i script a gui that gives a hat? (Already done remote function part)

Asked by 3 years ago

I've already done the gui parts, i made a button, linked it up so when clicked enables a remote event, server script service script picks it up you know the good stuff, So all i need to know now is how i would give the player a hat.

Event:WaitForChild("Halo").OnServerEvent:Connect(function(Player)
    local workspaceplr = game.Workspace:FindFirstChild(Player.Name)

this part of the script gets me the name of the player so i can find it in workspace. So if i need to edit its humanoid or any character in there i can, I tried googling it but i just didn't get the right results. Any help would be nice

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

You don't need to search for the Character in workspace; the initial act isn't as reliable as you'd think due to the potential complications of a name-based search. The Player object actually contains a reference to its respective Avatar through an attribute called 'Character', you can simply index that.


What you're looking for is the :AddAccessory() method of the Humanoid Instance. You will have to manually Instantiate the Instance you wish to add onto the Humanoid, as this method takes the physical object rather than an AssetID.


Side-note:

Assets within the Server are pre-loaded. On this end of the network, you don't need to worry about any load-latency with the Instances of your game, unless, under a special case, one wouldn't exist at the given time. You do not need to use :WaitForChild() to reference Halo, I suggest you simply write Event.Halo to reduce the unnecessary time-complexity.

0
Thanks! I totally forgot about the whole :addAccessory() Page, And your extra notes really helped! Thank you again! andypop12345 12 — 3y
Ad

Answer this question