The following script is in a localscript, and it all seems to work completely fine in solo, but completely breaks in online mode.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Torso = Player.Character.Torso
UpdateGrapple = false
Speed = 50
debounce = false


function WeighModel(Model)
	RawWeight = 0
	for i,v in pairs(Model:GetChildren()) do
		if v:IsA("BasePart") then
			RawWeight = RawWeight + v:GetMass()
		end
	end
	DividedWeight = RawWeight/7
	return DividedWeight
end

function Grapple(Location, MTar)
	if MTar == nil then return end
	Player.Character.Humanoid.Died:connect(function ()
		Container:Destroy()
		if Torso:FindFirstChild("RocketPropulsion") ~= nil then
			Torso.RocketPropulsion:Destroy()
		end
	end)
	Container = Instance.new("Model", game.Workspace)
	Container.Name = Player.Name.."Container"
	print("Firing grapple!")
	loc = Location.p
	distance = (loc - Torso.Position).magnitude
	print("Defined variables")
	Target = Instance.new("Part", Container)
	Target.Name = Player.Name.."Target"
	Target.Transparency = 1
	Target.FormFactor = Enum.FormFactor.Custom
	Target.Size = Vector3.new(.2, .2, .2)
	Target.Anchored = false
	print("Made target")
	W = Instance.new("ManualWeld", Target)
	W.Part0 = Target
	W.Part1 = MTar
	W.C0 = CFrame.new()
	W.C1 = MTar.CFrame-MTar.CFrame.p
	print("Welded target")
	Target.CFrame = Location
	RP = Instance.new("RocketPropulsion", Player.Character.Torso)
	RP.CartoonFactor = 1
	RP.Target = Target
	RP.MaxThrust = 7500
	RP.MaxTorque = Vector3.new(2000, 2000, 2000)
	RP.MaxSpeed = Speed
	RP:Fire()
	print("Made and fired RP. Starting the wire sequence")
	CharWeight = WeighModel(Player.Character)
	repeat
		loc = Target.Position
		Wire = Instance.new("Part", Container)
		Wire.Name = Player.Name.."Wire"
		Wire.BrickColor = BrickColor.new("Really black")
		Wire.Transparency = 0
		Wire.Anchored = true
		Wire.CanCollide = false
		Wire.TopSurface = Enum.SurfaceType.Smooth
		Wire.BottomSurface = Enum.SurfaceType.Smooth
		Wire.formFactor = Enum.FormFactor.Custom
		distance = (loc - Torso.Position).magnitude
		Wire.Size = Vector3.new(0.2, 0.2, distance)
		Wire.CFrame = CFrame.new(loc, Torso.CFrame.p) * CFrame.new(0, 0, -distance/2)
		wait()
		Wire:Destroy()
		CurrentVelocity = Torso.Velocity
	until UpdateGrapple == false
	Torso.Velocity = (CurrentVelocity + Vector3.new(0, 5, 0))*CharWeight
	print("Wire sequence ended.")
	print("Unlatched!")
	Container:Destroy()
	RP:Destroy()
end

Mouse.KeyDown:connect(function (Key)
    if Key == "q" then
        UpdateGrapple = true
        Grapple(Mouse.hit, Mouse.Target)
        print("Latched!")
    end
end)

Mouse.KeyUp:connect(function (Key)
    if Key == "q" then
        UpdateGrapple = false
        print("UpdateGrapple been set to false")
    end 
end)

Do I need to make them localfunctions and local variables for this to work?

3 comments

0

No, they are fine.. Can you tell me the output error? If there is none, Put prints in different spots and tell me what runs and what doesn't run.

0

It appears at line 3 I was trying to access the character which hadn't spawned yet, so I used WaitForChild to find an object in the workspace with the name of the player, so now it works.

0

okay good :D .. Yeah.. I dislike how you have to do that in local scripts..