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

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

Asked by 6 years ago

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)
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 theking48989987 2147 — 6y
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. User#25115 0 — 6y
0
If my answer helped out don't forget to hit that Accept Answer button. User#24403 69 — 6y

4 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

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)
0
only use hit.Parent:MoveTo(Vector3.new(x,y,z)) yHasteeD 1819 — 6y
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. User#24403 69 — 6y
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. M39a9am3R 3210 — 6y
0
*facepalm* really yHastee? Mirzadaswag 110 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
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!

0
MoveTo() will not work, CFrame should be used DeceptiveCaster 3761 — 6y
0
MoveTo() makes the player walk to the location DeceptiveCaster 3761 — 6y
0
please explain your answer instead of pasting a script, just pasting a script doesn't help anyone in the long term theking48989987 2147 — 6y
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

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.
0
finally somebody that doesn't use MoveTo() DeceptiveCaster 3761 — 6y
0
Thanks ???? GodsGraceSavesAll 6 — 6y
0
Lol I did an emoji and it did ???? instead GodsGraceSavesAll 6 — 6y
0
please explain your answer instead of pasting a script, just pasting a script doesn't help anyone in the long term theking48989987 2147 — 6y
0
Ok sorry I’m new GodsGraceSavesAll 6 — 6y
Log in to vote
0
Answered by 6 years ago

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.

Answer this question