Hello I am trying to make a brick that changes the players place when it is clicked on. Here is what I have so far.
function onClicked(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
game:GetService("TeleportService"):Teleport(5710227729,player)
end
end
script.Parent.Touched:connect(onClicked)
I am unsure of why this isn’t working. There isn’t even an error output that I can see.
I know it won’t run in studio. I have another script that runs when the button is stepped on and it outputs an error saying it cant run in studio. This one dosen’t output anything
Just out of interest, you named your function onClicked however you use the .Touched event and a hit argument. Is this definitely the right method, are players touching something or clicking something?
function onClicked(player)
if player then
game:GetService("TeleportService"):Teleport(5710227729,player)
end
end
script.Parent.MouseClick:Connect(onClicked)
In which case use the MouseClick function as shown here with a player argument, no need to get player from character just teleport the player from the argument.
This is presuming that script.Parent is of course a Click Detector.
function onClicked(player)
game:GetService("TeleportService"):Teleport(5710227729,player)
end
script.Parent.MouseClick:connect(onClicked)
for some reason its still not outputting a error message saying it cant be ran in studio. I even changed the “MouseClick” to “ClickDetector” (as thats what mine is called) and it still has no output
Can you screenshot the path please to the script and the click detector? Changing it to ClickDetector will not work as that’s the function which is registers as a click for. Make sure the detector is actually being clicked.
Having you now shown this, it would appear that you need to rename your ClickDetector back to something else so it doesn’t think you’re trying to MouseClick the brick, rename it back to ClickDetector and use the following code!
function onClicked(player)
game:GetService("TeleportService"):Teleport(5710227729,player)
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)```