Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I move this hat from ServerStorage to a character?

I want to move a hat out of the ServerStorage and onto a character. The code is in a LocalScript inside a TextButton:

player = game.Players.LocalPlayer.Character
for _, child in pairs(player:GetChildren()) do
    if child.ClassName == 'Hat' then
	child:destroy()
    end
end
local hat = game.ServerStorage.Customizer.Male.Hats.BlondeFaux:clone().Parent==player
hat.Handle.CFrame = player.Head.CFrame * CFrame.new(0, player.Head.Size.Y / 2, 0) * hat.AttachmentPoint:inverse()

When I run the game, I get the following error:

00:24:04.796 - Players.Player.PlayerGui.ScreenGui.Frame.Hat.Preview:4: attempt to index local 'hat' (a boolean value)

00:24:04.798 - Stack Begin

00:24:04.799 - Script 'Players.Player.PlayerGui.ScreenGui.Frame.Hat.Preview', Line 4

00:24:04.800 - Stack End

Thanks!

1 answer

✓ Accepted answer

Change:

local hat = game.ServerStorage.Customizer.Male.Hats.BlondeFaux:clone().Parent==player

To:

local hat = game.ServerStorage.Customizer.Male.Hats.BlondeFaux:clone()
hat.Parent = player

Also, do remember that double equals is comparison; you want to set it not check if the clone's parent is equal to the player's character.

2 comments

0

Thanks for the reply! After changing that line, it worked in Studio but still doesn't work in online. Any ideas as to why that is?

0

I completely missed that error; I do apologise. Another issue is that you need to move the hats to ReplicatedStorage - This is due to the fact that LocalScripts cannot access ServerStorage.

This discussion is preserved as it was. New answers, comments, and votes are closed.