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

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

Asked by 8 years ago

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

Log in to vote
0
Answered by
DataStore 530 Moderation Voter
8 years ago

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.

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? AmericanDev 10 — 8y
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. DataStore 530 — 8y
Ad

Answer this question