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

How exactly do local parts work, when using CFrame?

I've never understood it. Whenever i try to CFrame a local part, it moves somewhere completely different from where i want it to be... Help?

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		local bin = Instance.new("Message",char)
		local part = Instance.new("Part",bin)
		part.CFrame = CFrame.new(0,10,0)
	end)
end)

The code above puts it around my spawn instead of around the co-ordinates 0,10,0

I am REALLY confused.

3 comments

0

Players often spawn around the coordinates 0,0,0 so you might be checking it wrong. Look at it's properties instead.

0

I put a custom spawnpoint...

0

Oke. Try doing my answer.

2 answers

Try this and tell me if it works. objectspace is the position the character spawned at (measured at ground level), and positions the part to the given position by subtracting the objectspace.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(char)
	local objectspace  = char.Torso.Position - Vector3.new(0,3,0)
	local function coord(position)
		return position - objectspace
	end

        local bin = Instance.new("Message",char)
        local part = Instance.new("Part",bin)
        part.CFrame = CFrame.new(coord(Vector3,new(0,10,0)))
    end)
end)

CFrame has two parameters, both being Vector3 values. It can stuff up if your provide 3 values, or only one of them. Parameter 1 being it's position, and Parameter 2 being where it's facing.

part.CFrame = CFrame.new(Vector3.new(0,10,0),Part.Position + Vector3.new(0,0,2)) --the 2nd parameter: parts stuff up if you make them look at themselves :/

3 comments

0

Thanks, i'll try that.

0

Hmm, i think the local parts are placed locally to where the player is spawned... I'll try making a script that positions it based on the players spawnpoint subtracted by the CFrame of where i want it. (That way i can re-use it really easily <3)

0

I'll make it as simple as just placing the parts in a folder.

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