Hi! I’m pokeboss992! Today, I started a game called “Blox Run”, inspired by the classic series called “Run” you might see on game sites. As I said in the title, I’m trying to make a script that has a character change position when touching, sort of how the wall-jumping system works in the game I was inspired by.
As I said before, I made a script for changing the characters position when touching a part, but it doesn’t seem to work. Here’s my script:
script.Parent.Touched:connect(function(hit)
local player = hit.Parent
local wall = script.Parent.Orientation.Z
player.Torso.CFrame = CFrame.Angles(0,0,wall+90)
end)
Try this. First off, you want to rotate them, so you want to take their current CFrame and then add the CFrame.Angles to it. Then you also want to use math.rad, which converts degrees into what CFrame.Angles can use. I also would add a debounce so that they don’t go spining out of controls. If you have any questions about this feel free to ask.
local db = false
script.Parent.Touched:connect(function(hit)
local player = hit.Parent
local wall = script.Parent.Orientation.Z
if db == false then
db = true
player.Torso.CFrame = player.Torso.CFrame * CFrame.Angles(0,0,math.rad(wall+90))
wait(0.5)
db = false
end
end)
Try what @XdJackyboiiXd21 said but also include a check on the player to ensure the thing that is touching the part is the player itself. An easy way to go about doing this is
if hit.Parent:FindFirstChild('Humanoid') ~= nil then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
-- rest of your code
end
Although this is all correct, the most important part is that instead of setting the torso’s position, you should use :SetPrimaryPartCFrame() on the Player’s character, so you don’t kill the player.
Ahh, I get it! So the game just didn’t know that I was talking about angles, and it was converting the number into something different. Thanks a bunch!
script.Parent.Orientation.Z --will return the degree of the orientation on the Z axis. Then you change the Z axis by doing this:
CFrame.Angles(0,0,math.rad(wall+90))