1

# How do I teleport a model to the player?

Hello, I'm not an experienced scripter but I know a little about scripting and I'm working on my game here and I made a tool that whenever you activate it, it will teleport a horse model to your player, I'm having issues doing so and the script seems to not be working, Here is the script:

game.Players.PlayerAdded:Connect(function(player)
local Tool = script.Parent
local Horse = game.ServerStorage.Horse:Clone()
local char = player.Character
local characterCFrame = player.Character.HumanoidRootPart.CFrame
Tool.Activated:Connect(function()
Horse:SetPrimaryPartCFrame(characterCFrame)
end)
end)


The script is inside of the tool, which is inside of StarterPack. Any help would be very much appreciated, Thanks!

0

local Tool = script.Parent
local Horse = game.ReplicatedStorage.Horse:Clone()
local char = game.Players.LocalPlayer.Character
local characterCFrame = player.Character.HumanoidRootPart.CFrame
Tool.Activated:Connect(function()
Horse:PivotTo(characterCFrame)
end)

0
Hey don't say it like that he's still learning how to script. T3_MasterGamer 1047 — 12d
0
I learned to script both from youtube and experiencing scripting in Roblox Studio without knowlegde . T3_MasterGamer 1047 — 12d
0
hello my guy :) Puppynniko 983 — 12d
0
Sorry, I didn't see that he mentioned that he is learning scripting. GulgPlayer 17 — 12d
0

I don't recommend using Players.PlayerAdded because when you use to the tool, the horse might be teleported to all players instead of just you. Instead, get the Parent of the tool and check if it's a player. When the game starts, everything inside StarterPack will be transferred to the backpack of the players. If the player equip the tool, the tool leaves Player.Backpack and transferred to Player.Character. To check if the tool has been equipped, you use Tool.Equipped. This event returns a mouse, but it's optional.

To get the player's character, we simply get the Tool's Parent only if it's equipped. To detect if it's a real player, we simply do Players:GetPlayerFromCharacter() and check if it's nil (nothing/non-existent/null/void) or not.

And yes, the first person who answered this is correct: use PVInstance:PivotTo() and PVInstance:GetPivot() instead.

Make sure the script is a normal script.

So the final solution would be:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local Horse = ServerStorage.Horse
local Tool = script.Parent
Tool.Equipped:Connect(function(Mouse)
local Character = Tool.Parent
local Player = Players:GetPlayerFromCharacter(Character)

if Player ~= nil then -- checks if it's a real player
Tool.Activated:Connect(function()
local characterCFrame = Character:GetPivot()

local horseClone = Horse:Clone()
horseClone:PivotTo(characterCFrame)
end)
end
end)

0
Edited 11 days ago

weld a part to your entire model then teleport that part to wherever u want

local Tool = script.Parent
local Horse = game.ReplicatedStorage.Horse:Clone()
local char = game.Players.LocalPlayer.Character
local characterCFrame = player.Character.HumanoidRootPart.CFrame
Tool.Activated:Connect(function()
Horse.Parent = workspace
Horse.TPPart.CFrame = characterCFrame -- replace TPPart with your part thats welided to your model
end)

0
Edited 11 days ago

This could be done using RemoteEvent. you will need to create a RemoteEvent with any name then a script with this script:

local Tool = script.Parent
local RemoteFires = -- path of the remote event, Ex: Tool.RemoteEvent, Tool.Folder.RemoteEvent, Tool.Model.RemoteEvent, etc.

Tool.Activated:Connect(function()
local Player = game:GetService("Players")
local HumanoidPartCF = Player.LocalPlayer.Character.HumanoidRootPart.CFrame
RemoteFires:FireServer(HumanoidPartCF)
end)


then when it fires the remote event, the serverscript will detect it and gets the information about the event fired

local RemoteFires = -- path of the remote event, Ex: Tool.RemoteEvent, Tool.Folder.RemoteEvent, Tool.Model.RemoteEvent, etc.

RemoteFires.OnServerEvent:Connect(function(player, CFrame)
local CFramePlayer = CFrame
local CloneHorse =  game.ReplicatedStorage.Horse:Clone()
local parentclonedpart = CloneHorse
parentclonedpart.Parent = game.Workspace

local centerhorsepart = -- inside the horse, it must have a part where the whole horse model is welded to the part using WeldConstraint
centerhorsepart.CFrame = CFramePlayer

end)


This could maybe work, because i havent tested yet but hope this helps!