I am trying to make players walk on walls, and I have no idea what is wrong with my code. This is it:

function walkOnWall()
	local player = game.Players.LocalPlayer
	local character = player.Character
	
	local origin = character.Position + Vector3.new(0, 0.1, 0)
	
	local ray = Ray.new(origin, Vector3.new(0, -1, 0))
	local hit, pos, normal = workspace:FindPartOnRay(ray, character)
	
	local cross = Vector3.new(0, 1, 0):Cross(normal)
	local angle = math.asin(cross.magnitude)
	
	character:SetPrimaryPartCFrame(
		CFrame.new(character.Position + normal * character:GetModelSize().y/2)
		* CFrame.fromAxisAngle(cross.magnitude == 0 and Vector3.new(1) or cross.unit, angle)
	)
end

game:GetService("RunService").RenderStepped:connect(function()
	walkOnWall()
end)

and yes, it is in a local script.

6 comments

0

No lead. You simply provided a complicated script saying "It doesn't work." Is there an error? What about it doesn't work?

0

A tip is, try capitalizing the C in "connect

0

Roblox made an update at a time I do not know where they made it so for "connect" to work is only if it has a capital C, in case you were wondering.

0

I'm having studio try to see whats wrong because I'm pretty stumped (and if this script works ill use it for my game but thats unrelated) I haven't finished but it says on the line "().y/2)" studio says "Ambiguous syntax: this looks like an arguement list for a function call, but it could also be a start of a new statement" If you know what to do from further on out, try it.

0

update: i just realized on that line i was talking about up there was supposed to be in the same line above it .-.

0

last update & comment: studio says it is perfecto. when i test it in-game i just run into the block.