Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help with 2D platformer. Help?

Asked by 8 years ago

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.

0
so this? game.Worksapce[hit.Parent].Torso.CFrame = CFrame.new(Vector3.new(-43, 10, 13)) lucas4114 607 — 8y
0
@lucas. When i replace with that, i recieve "Workspace.Part.Script:4: bad argument #2 to '?' (string expected, got Object)" bizarresox 10 — 8y
0
[hit.Parent.Name]* not [hit.Parent] lucas4114 607 — 8y

1 answer

Log in to vote
1
Answered by
Sublimus 992 Moderation Voter
8 years ago

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)

Ad

Answer this question