Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I can't seem to make a fling script that works, please help me fix it if you see any errors?

local p = 100
local d = 0
local rand = math.random

function fling(hit)
	local char = hit.Parent
	if char:FindFirstChild("Humanoid") then
		local body = Instance.new("BodyPosition")
		body.Position = Vector3.new(rand(d,p),rand(d,p),rand(d,p))
		body.MaxForce = Vector3.new(p, p, p)
		body.Parent = char.HumanoidRootPart
		wait(.1)
		body.Parent = nil
	end
end
script.Parent.Touched:Connect(fling)

I have the script parented to the part but it doesn't fling me when I step on it. I've tried many other fling scripts online but they also don't seem to work either, here's another one I tried:

local n = 100
local rand = math.random

local function fling(hit)
	local char = hit.Parent
	if char:FindFirstChild("Humanoid") then
		char.HumanoidRootPart.Velocity = Vector3.new(
			rand(-n, n),
			rand(-n, n),
			rand(-n, n))
		n = n/10
		char.HumanoidRootPart.RotVelocity = Vector3.new(
			rand(-n, n),
			rand(-n, n),
			rand(-n, n)
		)
	end
end
script.Parent.Touched:Connect(fling)

2 comments

0

Last line (19) should be :Connect(fling(hit).

0

Nope, it tells me that there's an unknown global called "hit". Just calling fling is fine because there's no parameter being passed in.

2 answers

A simple fling script would be

function fling(player)
	player.Character.Humanoid.Sit = true
	player.Character.HumanoidRootPart.Velocity = Vector3.new(math.random(-200, 200), math.random(0, 200), math.random(-200, 200))
end

1 comment

0

It returns the error that "Character is not a valid member of MeshPart"

exxtremestuffs' answer would work for this situation but i think that OP may have just used the fling function wrong, considering that you got the error Character is not a valid member of MeshPart i would assume you just called fling on a limb of a character. to fix it i would do local plyr = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent) then call fling(plyr)

This discussion is preserved as it was. New answers, comments, and votes are closed.