I want to make a tool that summons a wall in front of the player. I already tried a script but it did not work, there was also no errors in the output.
here is my script
local tool = script.Parent local bool = game.StarterPack.Build.Value local player = game.Players.LocalPlayer local mouse = player:GetMouse() local torso = player.Character.UpperTorso --EQUIP-- tool.Equipped:connect(function() bool.Value = true end) tool.Unequipped:connect(function() bool.Value = false end) --WALL-- mouse.KeyDown:connect(function(key) if key == "e" and bool.Value ==true then print("Pressed e") Wall = Instance.new("Part",game.Workspace) Wall.Position = torso.Position + torso.Position + torso.CFrame.lookVector*5 end end)
.CFrame = torso.CFrame.lookVector*5 + torso.Position
KeyDown is deprecated. Don't use it. Instead do this.
local context = game:GetService("ContextActionService") local tool = script.Parent local plr = game:GetService("Players").LocalPlayer local char = plr.CharacterAdded:Wait() local bool = tool.Bool tool.Equipped:Connect(function(mouse) -- Use Connect not connect bool.Value = true end) tool.Unequipped:Connect(function() bool.Value = false end) -- Wall function function makeWall() if bool.Value == true then local W = Instance.new("Part",game.Workspace") W.Name = plr.Name.."'s Wall" W.CFrame = char.UpperTorso.CFrame + Vector3.new(1,0,0) end end context:BindAction("MakeWall",makeWall,false,Enum.KeyCode.E)
So you guys helped me make the script but like why didnt it spawn in front of the players face?
local context = game:GetService("ContextActionService") local tool = script.Parent local plr = game:GetService("Players").LocalPlayer local char = plr.CharacterAdded:Wait() local bool = tool.Value local torso = game.Players.LocalPlayer.Character.UpperTorso tool.Equipped:Connect(function(mouse) -- Use Connect not connect bool.Value = true end) tool.Unequipped:Connect(function() bool.Value = false end) -- Wall function function makeWall() if bool.Value == true then local W = Instance.new("Part",game.Workspace) W.Name = plr.Name.."'s Wall" W.Size = Vector3.new (13, 13, 2) W.Anchored = true W.CFrame = char.UpperTorso.CFrame + char.UpperTorso.CFrame.lookVector*5 + torso.Position end end context:BindAction("MakeWall",makeWall,false,Enum.KeyCode.E)
that was the code I used (thanks to you guys) but it does not spawn in front of the player, it like spawns on his left or right, and sometimes behind.