My script is supposed to pick up the player/ put them above you and weld them there. And it works the first time. Yet after the first time. Something happens and it will still go above the players head. But not at the same X and Z. it'll still be welded to you and move when you move. But it will be like 15 studs in front of you and 4 studs to the side. How do i fix this?
Script:
local event = game.ReplicatedStorage.KillPlayer
event.OnServerEvent:Connect(function(Player, FromP, ToP)
local RayCast = Ray.new(FromP, (ToP-FromP).unit*100)
local part = game.Workspace:FindPartOnRay(RayCast, Player.Character, false, true)
if part then
local char = part.Parent
local Hum = char.Humanoid
if Hum then
if not char:FindFirstChild("Weld") then
Hum.PlatformStand = true
char.HumanoidRootPart.CFrame = Player.Character.HumanoidRootPart.CFrame + Vector3.new(0, 3, 0)
local weld = Instance.new("Weld", char)
weld.Part0 = char.HumanoidRootPart
weld.Part1 = Player.Character.HumanoidRootPart
weld.C0 = char.HumanoidRootPart.CFrame:inverse()
weld.C1 = Player.Character.HumanoidRootPart.CFrame:inverse()
else
char:FindFirstChild("Weld"):Destroy()
end
end
end
end)
local script (So you can test it out and see what i mean)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Event = game.ReplicatedStorage.KillPlayer
mouse.Button1Down:Connect(function()
Event:FireServer(player.Character:FindFirstChild("HumanoidRootPart").Position, mouse.Hit.Position)
end)
How do I fix this?
Edit: Just figured out it doesnt work that well onn the first run either.
