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

How can I make it so a part spawns right next to a player?

Asked by 4 years ago

here is the script :

seed=script.Parent

seed.Activated:Connect(function() local i=Instance.new("Part",game.Workspace) i.BrickColor=Random i.Position = game.Players.LocalPlayer.Character.Torso.Position + Vector3.new(0,0,-5) seed:Destroy() end)

0
Because its in a local script it won't work so move it to a script and then find a diffrent way to get the torso of the player since localPlayer doesn't work in scripts deth836231 142 — 4y
0
have spaces between the equal signs front and back or it will not work Staven2u 2 — 4y
0
You should use either lookvector or rightvector. BuDeep 214 — 4y

1 answer

Log in to vote
0
Answered by
noammao 294 Moderation Voter
4 years ago

This should work, I think,

local seed=script.Parent
local offset = Vector3.new(0,0,-5)
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()

seed.Activated:Connect(function() 
local i = Instance.new("Part")
i.Parent = game.Workspace
i.BrickColor = BrickColor.Random()

i.Position = Character.HumanoidRootPart.Position + (Character.HumanoidRootPart.CFrame.lookVector * offset)
seed:Destroy()
end)

The reason that I don't set the parent of the new instance on line 7 is because it has been documented to cause performance issues. You can read about it here. Secondly you can't set the brick color as random. You have to use BrickColor.[Color] or set the brick color with a string.

Ad

Answer this question