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

My script displays a sword, but the sword isnt rotated right, fixes?

Asked by 4 years ago

Ok so I'm making a custom sword system and have made it so the weapon the player has displays on the side of their charater, the only problem is, if they are facting any direction, other than that at which they are spawned in, the sword isnt rotated correctly.

I know I'm missing some code or need to edit another bit of code, but am unsure as to what. Any help?

My current code is this:

while wait() do
    if not script.Parent:FindFirstChild("SwordDisplay") then
        local Plr = game.Players:GetPlayerFromCharacter(script.Parent)

        if not script.Parent:FindFirstChildOfClass("Tool") then
            local SG = Plr:WaitForChild("StarterGear")
            local Foundtool = SG:FindFirstChildOfClass("Tool")

            if Foundtool then
                local Handle = Foundtool.Handle

                local Clone = Handle:Clone()
                local NewWeild = Instance.new("Weld", Clone)
                NewWeild.Part0 = script.Parent.HumanoidRootPart
                NewWeild.Part1 = Clone
                Clone.Parent = script.Parent
                Clone.Name = "SwordDisplay"
                Clone.Orientation = Vector3.new(-17.5, 180, 0)
                Clone.Position = (script.Parent.HumanoidRootPart.Position + (script.Parent.HumanoidRootPart.CFrame.RightVector + script.Parent.HumanoidRootPart.CFrame.LookVector) * -1.05) - Vector3.new(0,1.5,0)
            end
        end
    end
end

3 answers

Log in to vote
0
Answered by 4 years ago

This is a never mind, Turns out I just had to edit the orientation to be the humanoidrootparts orientation at the y level + 180

revised code if anyone wishes to use it:

while wait() do
    if not script.Parent:FindFirstChild("SwordDisplay") then
        local Plr = game.Players:GetPlayerFromCharacter(script.Parent)

        if not script.Parent:FindFirstChildOfClass("Tool") then
            local SG = Plr:WaitForChild("StarterGear")
            local Foundtool = SG:FindFirstChildOfClass("Tool")

            if Foundtool then
                local Handle = Foundtool.Handle

                local Clone = Handle:Clone()
                local NewWeild = Instance.new("Weld", Clone)
                NewWeild.Part0 = script.Parent.HumanoidRootPart
                NewWeild.Part1 = Clone
                Clone.Parent = script.Parent
                Clone.Name = "SwordDisplay"
                Clone.Orientation = Vector3.new(-17.5, script.Parent.HumanoidRootPart.Orientation.Y + 180, 0)
                Clone.Position = (script.Parent.HumanoidRootPart.Position + (script.Parent.HumanoidRootPart.CFrame.RightVector + script.Parent.HumanoidRootPart.CFrame.LookVector) * -1.05) - Vector3.new(0,1.5,0)
            end
        end
    end
end
0
Btw its Y axis not level :/ Gingerely 245 — 4y
0
oof MrCatDoggo 213 — 4y
Ad
Log in to vote
0
Answered by
Gingerely 245 Moderation Voter
4 years ago

you had to orient it at the y level + 180 :xdd:

Log in to vote
0
Answered by 4 years ago

I have a add-on that fixes this. Here is the link: https://web.roblox.com/library/4921924503/Tool-Grip-Editor

0
Thats not what i meant, I've got that anyway. What i was looking for is part rotation as the display is the handle of the weapon MrCatDoggo 213 — 4y

Answer this question