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)
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)
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)
only use hit.Parent:MoveTo(Vector3.new(x,y,z))
Good job yHasteeD. Instead of being a jerk why don't you explain why to "only use" your method. Also using CFrame is better.
@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.
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!
MoveTo() will not work, CFrame should be used
MoveTo() makes the player walk to the location
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.
finally somebody that doesn't use MoveTo()
Thanks ????
Lol I did an emoji and it did ???? instead
please explain your answer instead of pasting a script, just pasting a script doesn't help anyone in the long term
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.
3 comments
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
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.
If my answer helped out don't forget to hit that Accept Answer button.