Running into an error when teleporting within a place with an onMouseClick event

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to change the HumanoidRootPart’s CFrame with a Mouse Click

  2. What is the issue? Include screenshots / videos if possible!

I’m getting an error clicking saying player is not a valid member of Workspace.I get the same error when just using HumanoidRootPart. I know these things aren’t members of the workspace but do I have to use global variables or am I missing something like Getplayerfromcharacter

Script:

  1. local clickDetector = script. Parent

  2. function onMouseClick()

  3.  game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0,5,0)
    
  4. end

  5. clickDetector.MouseClick:connect(onMouseClick)

  6. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried using Player.Character and Getplayerfromcharacter, probably incorrectly. I’ve looked for many solutions. Thank you for your time.

2 Likes

Are you using a local script or server script?

2 Likes

A normal script inside of the Click Detector. Probably not the best choice

2 Likes

Ok could you copy and paste the script to me so I can look?

2 Likes

Try this, I think it should work better for you.

local clickDetector = script.Parent

function onMouseClick(player)

player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0,5,0))

end

clickDetector.MouseClick:connect(onMouseClick)
2 Likes

I’ll try it thanks (30chaarrrssssss)

2 Likes