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

This does not give me the hat when I step on the part. Any idea why?

script.Parent.Touched:Connect(function(hit)
local player = workspace[hit.Parent.Name]
local plr = game.Players:GetPlayerFromCharacter(player)
local playermodel = hit.Parent:FindFirstChild("Humanoid")
if plr.TeamColor == game.Teams["Medical Department"].TeamColor then
		local dustmask = Instance.new("Accessory")
		dustmask.Name = "MDHat"
		local handle = Instance.new("Part")
		handle.Name = "Handle"
		handle.Size = Vector3.new(1, 0.8, 1)
		handle.Parent = dustmask
		local faceFrontAttachment = Instance.new("Attachment")
		faceFrontAttachment.Name = "FaceFrontAttachment"
		faceFrontAttachment.Position = Vector3.new(0, 0, -0.5)
		faceFrontAttachment.Parent = handle
		local mesh = Instance.new("SpecialMesh")
		mesh.Name = "Mesh"
		mesh.Scale= Vector3.new(1, 1, 1.05)
		mesh.MeshId = "rbxassetid://20928923"
		mesh.TextureId = "rbxassetid://20928919"
	mesh.Parent = handle
end

end)


I have checked, and I am on the correct team

1 comment

0

you have not set the parent of the hat

1 answer

I believe your problem is what saveourwolves said. You have not set the Parent property of dustmask (the Accessory), so the Parent is set to nil by default, and the mask does not appear. To fix this, you could do two things:

  1. Add the parent parameter to the Instance.new() function, so your line 6 would be:
local dustmask = Instance.new("Accessory", player)

However, I have been reading this, and there it says that this method can be slow (also I reccommend reading it; its helpful)

  1. Assign the parent of the dustmask This is quite simple, and you have already done it on the faceFrontAttachment and mesh, so you just have to add this line anywhere where you create the mask:
dustmask.Parent = player

I'm pretty sure that you already know this and you just forgot to assign the Parent of dustmask.

1 comment

0

The parent parameter of Instance.new is deprecated. I recommend that you assign the parent in a new line.

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