Is this script wrong?

If this is in the wrong category, sorry.

So we’re working on our rock, paper, scissor game with @Whiteiicat, but the teleporting is kind of broken. Is this our fault?

https://gyazo.com/9cea024ae09cfe3689f81a19e5ba76a1

Here’s the code:

local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:Connect(function(player)
	player.Character.HumanoidRootPart.Position = workspace.StageSpawn1.Position -- Change "Teleportpart" To your part name
	player.Character.Humanoid.WalkSpeed = 0
	player.Character.Humanoid.JumpPower = 0
end)

You should use variables to shorten down your code first of all.
Secondly, teleporting them to the part’s position will make it teleport inside of it, as that’s the center of it.
You can add a Vector3.new() and modify the Y axis.

If you want them to look a certain way after “teleporting”, you can change their CFrame instead of their position.

2 Likes

Thanks for the solution, as said I am new to scripting in Lua and now I shortened the code and edited it.

1 Like

Instead of using Position, you should use CFrame like @DecodedString said. And I would also suggest moving the part a bit up, so the player wouldn’t get stuck.

They wouldn’t get stuck if you know your math (by teleporting the player a bit above the part itself).

Yeah, but I mean, moving the part up is way easier.

Well, no, because they will still be teleported in the center of the part regardless.

He can always make an inivisible and non-collidable part to server as a position pinpoint, but there’s nothing wrong with working with a bit of math just makes you smarter :slight_smile:

Thanks for the reply, and yep I’m using math to solve it right now.

Thanks everyone! I finally managed to solve it!
Edit: I did this: player.Character.HumanoidRootPart.CFrame = script.Parent.Parent.CFrame + Vector3.new(0, 1, 0)

I’m not saying you shouldn’t learn the Math, but taking into consideration that he’s a beginner, it would be much simpler to just do this. And of course, you should defo try to learn the Math.

https://i.gyazo.com/e26c53dbf2a8cd190fd8d47ecb174760.gif

Great to hear it! Good luck developing!

Actually I am learning math but I mean I don’t know everything that is helpful in development.

Great! Math plays an integral role in programming, and you should defo learn it! But in minor cases like these, it would be more efficient to do it without Math. Just my opinion.

Yep, if you want to study computer science you definitely need to have good math.