Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a part appear in front of a Player?

Asked by 6 years ago

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)


0
It’s probably not working because you’re trying to parent a part to workspace by localscript, which won’t work. It might work if you parent it to the camera but that will only let the player with the tool see it. User#20279 0 — 6y

3 answers

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
6 years ago

.CFrame = torso.CFrame.lookVector*5 + torso.Position

0
thanks a ton! turbomegapower12345 48 — 6y
0
Note that you shouldn't even be using torso.Position. You should be using HumanoidRootPart.Position. Still works the same, but HumanoidRootPart's position never fluctuates (even when jumping) With animations, the uppertorso will bounce around which will make the position inaccurate. Just a tip. Fifkee 2017 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)
0
Thanks so much! turbomegapower12345 48 — 6y
0
I tried your script it worked fine but it does not spawn in front of the players face? turbomegapower12345 48 — 6y
0
scroll down to see fully turbomegapower12345 48 — 6y
Log in to vote
0
Answered by 6 years ago

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.

Answer this question