-
What I Want To Achieve: I want to make it so the wall part that is spawned in will turn and face the player.
-
The Issue: When I use the tool, the part spawned in is always in the same direction.
-
Solutions I have Tried: I have tried :Lerp, CFrame.LookAt, and LookVector
Video url: 2023-07-30 20-36-01
Client Code
local localPlayer = game:GetService("Players").LocalPlayer
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents")["Combat"]["Wall"]
local clonedPart
script.Parent.RequiresHandle = false
script.Parent.Equipped:Connect(function()
local hrp = script.Parent.Parent:WaitForChild("HumanoidRootPart")
local part = Instance.new("Part")
clonedPart = part
part.Transparency = 0.8
part.Parent = game:GetService("Workspace").CurrentCamera
spawn(function()
while clonedPart do
local pos = hrp.Position + hrp.CFrame.LookVector*5
part.CFrame = CFrame.new(pos, hrp.Position) * CFrame.new(0,-2.5,0)
task.wait(0.01)
end
end)
end)
script.Parent.Activated:Connect(function()
if not clonedPart then return end
local hrp = localPlayer.Character.HumanoidRootPart
local pos = hrp.Position + hrp.CFrame.LookVector*5
local ray = Ray.new(clonedPart.Position, Vector3.new(0, -0.5, 0))
local _, _, _, material = workspace:FindPartOnRayWithWhitelist(ray, {workspace.Terrain})
if material == Enum.Material.Air then return end
if material == Enum.Material.Water then return end
event:FireServer(clonedPart.Position, material, pos)
clonedPart:Destroy()
clonedPart = nil
end)
script.Parent.Unequipped:Connect(function()
if clonedPart then
clonedPart:Destroy()
clonedPart = nil
end
end)
Server Code
local wall = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents")["Combat"]["Wall"]
wall.OnServerEvent:Connect(function(plr, position, material, angle)
local currentTime = tick()
local LastUsed = wallCdList[plr] or 0
if currentTime - LastUsed > 30 then
local wallPart = game:GetService("ReplicatedStorage")["Earth Wall"]:Clone()
wallPart.Material = material
if material == Enum.Material.Asphalt then
wallPart.Color = Color3.fromRGB(115, 123, 107)
elseif material == Enum.Material.Basalt then
wallPart.Color = Color3.fromRGB(30, 30, 37)
elseif material == Enum.Material.Brick then
wallPart.Color = Color3.fromRGB(138, 86, 62)
elseif material == Enum.Material.Cobblestone then
wallPart.Color = Color3.fromRGB(132, 123, 90)
elseif material == Enum.Material.Concrete then
wallPart.Color = Color3.fromRGB(127, 102, 63)
elseif material == Enum.Material.CrackedLava then
wallPart.Color = Color3.fromRGB(232, 156, 74)
elseif material == Enum.Material.Glacier then
wallPart.Color = Color3.fromRGB(101, 176, 234)
elseif material == Enum.Material.Grass then
wallPart.Color = Color3.fromRGB(158, 162, 158)
elseif material == Enum.Material.Ground then
wallPart.Color = Color3.fromRGB(107, 106, 101)
elseif material == Enum.Material.Ice then
wallPart.Color = Color3.fromRGB(129, 194, 224)
elseif material == Enum.Material.LeafyGrass then
wallPart.Color = Color3.fromRGB(158, 162, 158)
elseif material == Enum.Material.Limestone then
wallPart.Color = Color3.fromRGB(206, 173, 148)
elseif material == Enum.Material.Mud then
wallPart.Color = Color3.fromRGB(44, 42, 40)
elseif material == Enum.Material.Pavement then
wallPart.Color = Color3.fromRGB(70, 67, 64)
elseif material == Enum.Material.Rock then
wallPart.Color = Color3.fromRGB(102, 108, 111)
elseif material == Enum.Material.Salt then
wallPart.Color = Color3.fromRGB(198, 189, 181)
elseif material == Enum.Material.Sand then
wallPart.Color = Color3.fromRGB(143, 126, 95)
elseif material == Enum.Material.Sandstone then
wallPart.Color = Color3.fromRGB(137, 90, 71)
elseif material == Enum.Material.Slate then
wallPart.Color = Color3.fromRGB(63, 127, 107)
elseif material == Enum.Material.Snow then
wallPart.Color = Color3.fromRGB(195, 199, 218)
elseif material == Enum.Material.WoodPlanks then
wallPart.Color = Color3.fromRGB(139, 109, 79)
end
wallPart.CFrame = CFrame.new(position)
wallPart.Parent = game:GetService("Workspace")
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local goal1 = {Size = Vector3.new(1.25, 15.125, 12.5)}
local goal2 = {Size = Vector3.new(1.25, 0, 12.5)}
tweenService:Create(wallPart, tweenInfo, goal1):Play()
spawn(function()
task.wait(10)
tweenService:Create(wallPart, tweenInfo, goal2):Play()
task.wait(0.5)
repeat
wallPart.Transparency += 0.05
task.wait(0.01)
until wallPart.Transparency >= 1
wallPart:Destroy()
end)
end
end)
Sorry for how long the scripts are, any help would be appreciated, thank you!