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

How do I make this climbing script work properly?

EDIT: I found a solution that worked. Look at answers

I'm trying to make a script to make the player climb when a part has an easily settable property, but it's not working. I'm so confused.

To clarify, I want to be able to have a variable be true when touching the parts, and false when not. This specifically has to work with every part, which could have the same name, material, or be in a folder.

I also want G to have to be pressed for it to work

This is the code I've got currently;

local plr = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")

local gDown = false --pressing g or not
local wTouch = false --touching wall or not
local climb = false --climb false or not

local wall = workspace.Walls:GetChildren() --get the Walls folder's children

uis.InputBegan:Connect(function(key, isTyping) --get G key press
	if key.KeyCode == Enum.KeyCode.G then
		gDown = true
		print("gdown true")
	end
end)

uis.InputEnded:Connect(function(key, isTyping) -- lose G key press
	if key.KeyCode == Enum.KeyCode.G then
		gDown = false
		print("gdown false")
		climb = false
	end
end)

wall.Touched:Connect(function(hit)--check when walls are touched (broken, the focus)
	if hit.Parent:FindFirstChild("Humanoid") then
		print("touching wall")
	end
end)

If you don't have a fix for this but DO have a similar script that works close enough, PLEASE tell me. I want ANYTHING that could just get the result.

Priority is adding force. I can figure out orientation separately, if needed.

2 answers

"wall" is a table, so doing wall.Touched won't work

Instead, just loop through each wall(part) in wall(table) and connect the .Touched Event

for i,v in pairs(wall) do
	v.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			print("touching wall")
		end
	end)
end

1 comment

0

I actually just found a solution that involved raycasts that worked extremely well, but thanks for the answer

Found a method that worked myself. Hope this helps anyone that sees this

while wait(0) do --makes sure the raycast continues casting
	local raycastResult = workspace:Raycast(plr.Character.Head.Position, plr.Character.Head.CFrame.LookVector * 5)--(origin, direction)

	if raycastResult then --checks if raycast hits anything
		if raycastResult.Material == Enum.Material.Grass then --checks if raycast hits the "Grass" material
			wTouch = true --says wall is touched
			print("touching")
		end
	else
		wTouch = false --says wall is not touched
		print("no")
	end
end 

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