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

Hats Rotating Around Body?

Asked by
Ryzox 220 Moderation Voter
9 years ago

Okay so I have been creating a script over the past hour or so and I'm trying to figure out how to do this. I'm basically winging it as I go along. I've looked at some admin tablet scripts and saw how they used CFrame but I really want to use BodyPosition for nice smooth movements. Okay so here's what's wrong. For some reason the ClickDetector isn't working, and when I click on that hat it should create a hat inside my character and place it on my head, and also the fact that I am not sure how to make more than one hat appear and/or how to use the table to add or remove the hats. I am also unsure how to make them rotate around my body... I know I am asking quite a lot but it's probably quite easy for you more advanced scripters to answer for me and possibly explain. Here's my script so far:

Player = game.Players.LocalPlayer
Char = Player.Character
if not Char or not Char.Parent then
    Char = Player.CharacterAdded:wait()
end
Mouse = Player:GetMouse()
Hats = {}

function CreateTab(Name,TextureID,MeshID,AttachPos)
    local Tab = Instance.new("Part",Char)
    Tab.BottomSurface = "Smooth"
    Tab.TopSurface = "Smooth"
    Tab.Size = Vector3.new(2,2,2)
    local BodyPos = Instance.new("BodyPosition",Tab)
    local Update = coroutine.wrap(function()
        while wait() do
            BodyPos.position = Char.Torso.Position + Vector3.new(0,0,5)
        end
    end)
    Update()
    local PointLight = Instance.new("PointLight", Tab)
    PointLight.Color = BrickColor.new("Bright blue").Color
    PointLight.Range = 10
    local Mesh = Instance.new("SpecialMesh",Tab)
    Mesh.MeshType = "FileMesh"
    Mesh.MeshId = "http://www.roblox.com/asset/?id="..MeshID
    Mesh.TextureId = "http://www.roblox.com/asset/?id="..TextureID
    local ClickDetector = Instance.new("ClickDetector",Tab)
    ClickDetector.MaxActivationDistance = math.huge
    ClickDetector.MouseHoverEnter:connect(function(plr)
        if plr.Name == Player.Name then
            Tab.Transparency = 0.5
        end
    end)
    ClickDetector.MouseHoverLeave:connect(function(plr)
        if plr.Name == Player.Name then
            Tab.Transparency = 0
        end
    end)
    ClickDetector.MouseClick:connect(function(plr)
        if plr.Name == Player.Name then
            local h = Instance.new("Hat")
            local p = Instance.new("Part")
            h.Name = Name
            p.Parent = h
            p.Position = Char.Head.Position
            p.Name = "Handle" 
            p.formFactor = 0
            p.Size = Vector3.new(1, 0.4, 1) 
            p.BottomSurface = 0 
            p.TopSurface = 0 
            p.Locked = true 
            script.Parent.Mesh:clone().Parent = p
            h.Parent = Char
            h.AttachmentForward = Vector3.new (-0, -0, -1)
            h.AttachmentPos = Vector3.new(AttachPos)
            h.AttachmentRight = Vector3.new (1, 0, 0)
            h.AttachmentUp = Vector3.new (0, 1, 0)
        end
    end)
end

Player.Chatted:connect(function(msg)
    if msg:lower() == "load" then
        CreateTab("TwistedTurquoise",211828518,16627529, 0, 0, 0)
    end
end)

I have not played ROBLOX in a few months and am just getting back in to scripting so please forgive if I am making pretty basic mistakes.

And yes it is in a LocalScript

Answer this question