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

How do you change the CFrame of a Player?

Hi I made a script which when a Player other then the carrier touches the part it deals them 30 Damage and sends them flying back whilst rotating, But I don't know how to change the CFrame of a Player can you help me Please?

local WindSphere = script.Parent
WindSphere.Touched:connect(function(Brick)
	local Hum = Brick.Parent:findFirstChild("Humanoid")
	local Player = game:GetService'Players'.LocalPlayer
	if (Hum ~= nil)then
		Hum.Health = Hum.Health - 30
		Player.CFrame = 0  -- I know that's how how you do it, so I'm leaving it like that on purpose
	end
end)

1 comment

0

instead of player.CFrame you would have to do something like, Player.Vector3.new = 0 something like that

1 answer

You have to change the CFrame of the torso. Since all the limbs are welded to the torso the entire character will move:

local WindSphere = script.Parent
WindSphere.Touched:connect(function(Brick)
    local Hum = Brick.Parent:findFirstChild("Humanoid")
    local Player = game:GetService'Players'.LocalPlayer
    if (Hum ~= nil)then
        Hum.Health = Hum.Health - 30
        Player.Character.Torso.CFrame = CFrame.new(1,1,1)
    end
end)

2 comments

0

You can also use MoveTo() which will move the whole character

0

Erm, How do you do so the Cframe is added, E.g if the CFrame is 3,3,3 I want to add 0,2,0 to it, but without doing it manually all the time, so I don't keep having to type in a new position, it just sends them that way

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