My script makes creates a RocketPropulsion to the character. The script is in StarterCharacterScripts. I need to RocketPropulsion to be parented to the character that fired the event, but it creates a RocketPropulsion to every player. How do I make it only for the player that fired the event?
local rp = game:GetService("ReplicatedStorage")
local Fire = rp:WaitForChild("Fire")
local Abort = rp:WaitForChild("Abort")
local Fin = rp:WaitForChild("FinishAnim")
local Active = false
local Char = script.Parent
function gethumanoids()
local humanoidpos = {}
for i,x in pairs(workspace:GetChildren()) do
if x:FindFirstChild("Humanoid") and x~= Char and x.Humanoid.Health ~= 0 then
table.insert(humanoidpos, (Char.HumanoidRootPart.Position - x.HumanoidRootPart.Position).magnitude)
end
end
table.sort(humanoidpos)
for i,x in pairs(humanoidpos) do
if i ~= 1 then
table.remove(humanoidpos,i)
end
end
for i,x in pairs(workspace:GetChildren()) do
if x:FindFirstChild("Humanoid") and x ~= Char then
if (Char.HumanoidRootPart.Position - x.HumanoidRootPart.Position).magnitude == humanoidpos[1] then
return x
end
end
end
end
Fire.OnServerEvent:Connect(function(character)
print'Fire Recieved'
if gethumanoids() == nil then
print"no humanoid found"
Fin:FireClient(character)
return
end
local RocketPropulsion = Instance.new("RocketPropulsion")
print'created rocket'
RocketPropulsion.Parent = Char.HumanoidRootPart -- When I parent it to char, it parents to everyone, because char is script.Parent, and the Parent is StarterCharacterScripts
RocketPropulsion.MaxSpeed = 70
RocketPropulsion.MaxThrust = 100000
RocketPropulsion.TargetRadius = 1.5
RocketPropulsion.CartoonFactor = 1
Char.HumanoidRootPart.RocketPropulsion.Target = gethumanoids().HumanoidRootPart
print'targets aqurired'
Char.Humanoid.PlatformStand = true
Char.HumanoidRootPart.RocketPropulsion:fire()
print'fired'
RocketPropulsion.ReachedTarget:Wait()
print'destination reached'
RocketPropulsion:Abort()
Char.Humanoid.PlatformStand = false
RocketPropulsion:Destroy()
Fin:FireClient(character)
end)
local function AbortRocket(character)
local RocketPropulsion = Char.HumanoidRootPart:WaitForChild("RocketPropulsion")
RocketPropulsion:Abort()
Char.Humanoid.PlatformStand = false
RocketPropulsion:Destroy()
end
Abort.OnServerEvent:Connect(AbortRocket)
