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

Need help with 2D platformer. Help?

I am making a 2D platformer game, I have nailed the control and camera, I just need help with the teleport lava (Lava that TP's you to start) scripts. Currently I have this

function onTouched(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then -- Because object "hit" is just "Left Leg" or "Right Leg"
		game.Workspace.???.Torso.CFrame = CFrame.new(Vector3.new(-43, 10, 13))
	end
end

script.Parent.Touched:connect(onTouched)

The ??? is what I am stuck on. I need help on identifying a certain Instance by Name, not ClassName.

3 comments

0

so this? game.Worksapce[hit.Parent].Torso.CFrame = CFrame.new(Vector3.new(-43, 10, 13))

0

@lucas. When i replace with that, i recieve "Workspace.Part.Script:4: bad argument #2 to '?' (string expected, got Object)"

0

[hit.Parent.Name]* not [hit.Parent]

1 answer

✓ Accepted answer

If you are just trying to get the torso of the player that touched it, just use hit.Parent since that would point to the character object.

function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then -- Because object "hit" is just "Left Leg" or "Right Leg"
        hit.Parent.Torso.CFrame = CFrame.new(Vector3.new(-43, 10, 13))
    end
end

script.Parent.Touched:connect(onTouched)

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