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

Not using .Position correctly?

I'm trying to create an object that will float above somebodies head, but when I do it always appears far off, directly behind the player. Can anybody tell me why this script doesn't work and point me in the right direction?

local bomb = script.Parent
local head = script.Parent.Parent
while wait(0.01) do
	bomb.Position = head.Position + Vector3.new(0, 2, 0)
end

EDIT: Here's the script I'm using to spawn the bomb in at a certain time

if pwrup == "nuke" then
	local char = workspace:FindFirstChild(player.Name)
	local bomb = game.Lighting.Bomb:Clone()
	bomb.Parent = char.Head
end

When I check the workspace the bomb is a child of my Head part, but the bomb just sits on the ground not doing anything.

1 answer

You are adding two values that aren't formatted the same. You need to add the numbers inside the vector3.new. As so:

bomb.Position = Vector3.new(0 + head.Position.X, 2 + head.Position.Y, 0 + head.Position.Z)

Though i'm not sure why you would be encountering the problem where its floating behind the player. Is there other code you aren't showing? Maybe show an image of what the results are?

6 comments

0
0

is it in the same spot every time? If so its likely the problem i've addressed (Its position is just being set to 0, 2, 0 because the values cant add). If not then im at a complete loss.

0

Yea, it's in that exact spot every time

0

ok then use my solution, it should work

0

Also another thing, never use workspace:FindFirstChild(player.Name) to get the Character of a player. If an object and a players name match then, problems. Use player.Character instead.

0

okay!

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