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

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

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

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

2 comments

0

Btw its Y axis not level :/

0

oof

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