Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

3 comments

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

0

have spaces between the equal signs front and back or it will not work

0

You should use either lookvector or rightvector.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.