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

Help w/ adding part 10 studs above head?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

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

Log in to vote
2
Answered by 8 years ago

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.

0
Does not work FiredDusk 1466 — 8y
1
Work now ScripterGame 145 — 8y
Ad
Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

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
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 FiredDusk 1466 — 8y
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 Validark 1580 — 8y
0
I did that, it does not work FiredDusk 1466 — 8y
0
If he never do this he can't fix it by hisself you need more explication. XToonLinkX123 580 — 8y

Answer this question