Help with ability script

I’m trying to make a brick wall spawn in front of the character who activates the ability and every time the player activates the ability which fires the event the wall spawns in the same position how could I make the position change to the players position every time its activated?

local SS = game:GetService("ServerScriptService")
local RS = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Tool = script.Parent.Parent
local Utility = Tool:FindFirstChild("Utility")

Utility.Ability.OnServerEvent:Connect(function(Player)
	
	local Char = Player.Character
	local StartPos = Char.HumanoidRootPart.CFrame.Position
	local Orientation = Char.HumanoidRootPart.CFrame.LookVector
	print(StartPos)
	print(Orientation)

	local Wall = RS.Abilities.BrickHammer.BrickWall
	local Clone = Wall:Clone()
	
	Clone.Parent = game.Workspace
	Clone.Position = Vector3.new(StartPos) + Vector3.new(10,0,0)
	Clone.Orientation = Vector3.new(Orientation)
	
end)

You should use the CFrame property of the BasePart instead so that way you’re able to both Move, and Rotate the part that you want changed (Or your Wall) rather than changing both the Orientation, and Position properties individually

local SS = game:GetService("ServerScriptService")
local RS = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local Tool = script.Parent.Parent
local Utility = Tool:FindFirstChild("Utility")

Utility.Ability.OnServerEvent:Connect(function(Player)
    local Char = Player.Character
    local HRP = Char:WaitForChild("HumanoidRootPart")

    local Wall = RS.Abilities.BrickHammer.BrickWall:Clone()
    Wall.CFrame = HRP.CFrame * CFrame.new(0, 0, -10)
    Wall.Parent = workspace
end)

Another thing I’d recommend, is setting the .Parent property of your Wall variable last to minimize stressing out the engine as what you’re using now is the same as Instance.new("Part", workspace), which is what we don’t want

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.