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

When a wall is placed it is tilted forward?

So basically I am making a Naruto Game and i decided to make a Mud Wall Jutsu. This script works fine except when i press E to build the wall while walking the wall is tilted forward since my avatars body is tilted forward while moving. I wanted to know if there is a way to fix this?

local repStorage = game:GetService('ReplicatedStorage')
local WallBuild = repStorage:WaitForChild('RemoteEvents').ClientToServerWallBuild

WallBuild.OnServerEvent:Connect(function(player)
	local chr = player.Character
	local torso = chr.UpperTorso
	print(player.Name..' Fired A Jutsu!')

	local MudWall = Instance.new('Part')
	MudWall.Color = Color3.fromRGB(106, 87, 52)
	MudWall.Material = Enum.Material.Slate
	MudWall.Anchored = true
	MudWall.CanCollide = true
	MudWall.Size = Vector3.new(42, 21, 2)
	MudWall.Position = torso.Position + torso.CFrame.lookVector * 5
	MudWall.Rotation = torso.Rotation
	MudWall.Parent = game.Workspace
	
	print('end')
end)

1 answer

✓ Accepted answer

Instead of torso, use HumanoidRootPart as it is never tilted:

local repStorage = game:GetService('ReplicatedStorage')
local WallBuild = repStorage:WaitForChild('RemoteEvents').ClientToServerWallBuild

WallBuild.OnServerEvent:Connect(function(player)
    local chr = player.Character or player.CharacterAdded:Wait() --error proofing
    local root = chr.HumanoidRootPart
    local torso = chr.UpperTorso
    print(player.Name..' Fired A Jutsu!')

    local MudWall = Instance.new('Part')
    MudWall.Color = Color3.fromRGB(106, 87, 52)
    MudWall.Material = Enum.Material.Slate
    MudWall.Anchored = true
    MudWall.CanCollide = true
    MudWall.Size = Vector3.new(42, 21, 2)
    MudWall.CFrame = root.CFrame + torso.CFrame.lookVector * 5 
	-- you can use CFrame instead of Position and Rotation seperately (adding vector3 to CFrame is allowed)
    MudWall.Parent = game.Workspace

    print('end')
end)

2 comments

0

Thank you! Also do you know how i would make the part not halfway underground? (If you could do another answer that would rock cause then i actually get the notification

0

Sorry but that would be rather complicated, especially if your terrain is not flat (or you are planning it to be not flat). I think your best bet would be raycasting to measure a distance to the ground.

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