So, in my game, I would like it so that a player can click on an NPC and carry them. I am unsure how to approach this. So far, I have tried, cloning the NPC and cloning a copy of the NPC out of ServerStorage
(Without a script and click detector in) and welding it to the player’s HumanoidRootPart
however this has made the player unable to turn unless in first person and then the player ‘slides’ along the ground and snaps back if you exit.
It is also incredibly easy to get stuck with it attached to you, I have tried to fix it by disabling CanCollide
(It is easy to get stuck) on everything is to remove the Humanoid
but then after a few seconds, the entire model disappears (I believe the weld breaks). I have also tried making the NPC massless = true
however, this had no effect.
Current progress
To achive what I have done currently the server detects a players click and clones the NPC into the Character (game.Workspace
) and localy welding and positioning it on the Character.
Server script inside the original NPC:
local function onClick(player)
local sailor = game.ServerStorage.Missions.SailorRescue1.Sailor
local sailorClone = sailor:Clone()
sailorClone.Parent = game.Workspace:FindFirstChild(player.Name)
end
script.Parent.ClickDetector.MouseClick:Connect(onClick)
Local script inside StarterGui
- so PlayerGui
ingame
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
repeat
wait()
until Character:FindFirstChild("HumanoidRootPart")
local sailor = Character:WaitForChild("Sailor")
sailor.HumanoidRootPart.Anchored = false
sailor.HumanoidRootPart.CFrame = Character.HumanoidRootPart.CFrame
local Weld = Instance.new("Weld", sailor.HumanoidRootPart)
Weld.Part0 = Character.HumanoidRootPart
Weld.Part1 = sailor.HumanoidRootPart
Weld.C1 = CFrame.new(0, -2, -1)
Weld.C0 = CFrame.new()
(I haven’t rotated it yet, it is meant to be a fireman’s lift)
Ideally, the player should click the NPC, the NPC appears to be given a firemans lift on the back of the player (locally or server side) without getting stuck and be able to walk around normally.
Any ideas are welcome.