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

Help w/ adding part 10 studs above head?

Its not adding the part.

function onPlayerEntered(player)

player.CharacterAdded:connect(function(char)
while wait() do
	script.Parent.CFrame = CFrame.new(char.Torso.Positon, char.Head.Position + 1, char.Torso.Position)

end
end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

2 answers

✓ Accepted answer

CFrame take 12 numbers.The first three numbers are the Position and the nine others are for the rotation.

You can set a CFrame like this:

local part = Instance.new("Part", workspace)
part.Anchored = true
part.CFrame = CFrame.new(10, 5, 10)

for set the position its not really hard you can use CFrame.Angles or again CFrame.fromEulerAnglesXYZ

in theses function you'll need to put the rotation you want to have for the part. We'll take the exemple from later an change it.

local part = Instance.new("Part", workspace)
part.Anchored = true
part.CFrame = CFrame.new(10, 5, 10) *CFrame.Angles(0, math.pi/2, 0)

math.pi mean 90 degree, if you remove / 2 It'll be 180 degree. The number ?(pi) is a mathematical constant, the ratio of a circle's circumference to its diameter, commonly approximated as 3.14159. But you dont really need math.pi for set the rotation you can use math.rad another function in the math library.

local part = Instance.new("Part", workspace)
part.Anchored = true
part.CFrame = CFrame.new(10, 5, 10) *CFrame.Angles(0, math.rad(90), 0)

It'll does like later nothing change excepted your code. For CFrame.fromEulerAnglesXYZ Its the same thing as CFrame.Angles but CFrame.Angles is shorter and more easy to remember :3.You can also go on wiki if you want to know more on CFrame.

Now let's fix your code.

this part you've made take three position in a position you have three number(X, Y, Z) so we'll take these number and change it.You're error:

script.Parent.CFrame = CFrame.new(char.Torso.Positon, char.Head.Position + 1, char.Torso.Position)

and now It'll look like this

script.Parent.CFrame= CFrame.new(char.Torso.Position.X, char.Head.Position.Y + 1, char.Torso.Position.Z)

for your code its really simple you'll only need to change ^this part for the emplacement of your error.

Your code fix.

function onPlayerEntered(player)

player.CharacterAdded:connect(function(char)
while wait() do
    script.Parent.CFrame= CFrame.new(char.Torso.Position.X, char.Head.Position.Y + 1, char.Torso.Position.Z)

end
end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)


PS.: I see another error from your grammar from Positon you just need to change it for Position, a grammar error can be fatal in your code :s.

2 comments

0

Does not work

1

Work now

Your problem is here

CFrame.new(char.Torso.Positon, char.Head.Position + 1, char.Torso.Position)

You forgot to specify which coordinate, instead you put in the full position for each point.

Add in .X, .Y, and .Z after Position so the script knows which coordinate to look for.

EDIT

Like so:

char.Torso.Position.X -- This finds the X coordinate of the Torso position

4 comments

0

How would I do that? Or you change up the script for me so you can get an accepted answer and an upvote :) Thanks btw

0

@PreyStar I'll show you how to do it so you can understand for yourself, and fix your script yourself, because i want to make sure you learn from this

0

I did that, it does not work

0

If he never do this he can't fix it by hisself you need more explication.

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