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

Why am i not getting teleported if i touch the brick is Roblox Studio broken?

I think i wrote everything rigth why is it not working Here's the script:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
	Vector3.new(5.66, 0.715, 15.34)
end
end)

3 comments

1

having a line saying "Vector3.new(5.66, 0.715, 15.34)" just defines a vector3 value and doesn't use it for anything, you have to use the SetPrimaryPartCFrame function of models

0

If your code doesn't work, you should never automatically assume it is the IDE's fault. Generally, it is your (the programmer's) fault.

0

If my answer helped out don't forget to hit that Accept Answer button.

4 answers

Read upon CFrame and Model

The links above will help you understand the code below.

Here is the fix to your situation


script.Parent.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent:SetPrimaryPartCFrame(CFrame.new(5.66, 0.715, 15.34))
	end

end)

4 comments

0

only use hit.Parent:MoveTo(Vector3.new(x,y,z))

0

Good job yHasteeD. Instead of being a jerk why don't you explain why to "only use" your method. Also using CFrame is better.

1

@yHasteeD Problem with MoveTo is it will stack players on top of whatever occupies things in the space of where the character should pop into. This script ignores that scenario and moves the player's torso to that position.

0

facepalm really yHastee?

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent:MoveTo(Vector3.new(5.66, 0.715, 15.34))
    end
end)

This should fix your problem!

3 comments

0

MoveTo() will not work, CFrame should be used

0

MoveTo() makes the player walk to the location

0

please explain your answer instead of pasting a script, just pasting a script doesn't help anyone in the long term

Hello here is another script that works too!

place = CFrame.new(0,0,0) -- Where you want the player to go on touched
script.Parent.Touched:connect(function(p)--Creating the function
local humanoid = p.Parent:findFirstChild("Humanoid")--Trying to find the humanoid
if (humanoid ~= nil) then -- Checking if what touched it IS a player.
humanoid.Torso.CFrame = place -- Moves the torso to what is specified in the place variable
end
end)--Ending the fuction, if you see on the function line above there is an unclosed parenthesis that I am closing here.

5 comments

0

finally somebody that doesn't use MoveTo()

0

Thanks ????

0

Lol I did an emoji and it did ???? instead

0

please explain your answer instead of pasting a script, just pasting a script doesn't help anyone in the long term

0

Ok sorry I’m new

#An explanation The other answers did not explain what was wrong with your script. theking48989987 gave a good explanation as to why. You called Vector3.new but never did anything with the result of the call. So what you should do is make a model:SetPrimaryPartCFrame(cf) call which sets the CFrame of a models primary part to the CFrame cf.


#The code

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent:SetPrimaryPartCFrame(CFrame.new(5.66, 0.715, 15.34))
    end
end)

#Why use CFrame over Vector3 ######(in this case at least)

Now, the reason why to use CFrame over Vector3. M39a9am3R gave a good explanation. His explanation in short, is Vector3 factors in collision where CFrame does not. Additionally, CFrames hold both position and rotation information, so if you need to rotate the model you may if you wish.

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