My friend made this fling script, and it worked in a test game, but not in the main game it should be in.
local players = game:GetService("Players")
local runService = game:GetService("RunService")
function fling(player)
print(player) -- This also does too! no matter the command, it will print the player
local character = player.Character
if not character or not character.PrimaryPart or not character.Humanoid then return end
local flingDirection = (CFrame.Angles(math.random() * math.pi + (math.pi / 2), math.random() * math.pi * 2, 0) * CFrame.new(1, 0, 0)).Position
local flingPower = 200
local rotatePower = 50
local bodyVelocity = Instance.new("BodyVelocity")
local bodyAngularVelocity = Instance.new("BodyAngularVelocity")
bodyVelocity.Velocity = flingDirection * flingPower
bodyAngularVelocity.AngularVelocity = flingDirection * rotatePower
task.spawn(function()
runService.Heartbeat:Wait()
bodyVelocity:Destroy()
bodyAngularVelocity:Destroy()
end)
end
players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
msg = string.lower(msg)
msg = string.split(msg, " ")
if msg[1] == "/fling" then
print("fart") -- this prints fine!
if msg[2] ~= nil then
if msg[2] == "all" then
for _, player in pairs(players:GetPlayers()) do
fling(player)
end
elseif type(msg[2]) == "string" then
local MatchPlayer = nil
local MatchStart = math.huge
for _, CheckPlayer in pairs(players:GetPlayers()) do
local CheckStart = string.find(string.lower(CheckPlayer.Name), msg[2])
if CheckStart ~= nil and CheckStart < MatchStart then
MatchPlayer = CheckPlayer
MatchStart = CheckStart
end
end
if MatchPlayer then fling(MatchPlayer) end
end
else
fling(player)
end
end
end)
end)
Im not sure why or whats wrong, im not a good scripter so i dont really understand anything. but if you tell me how to fix this, i can.
local players = game:GetService("Players")
local runService = game:GetService("RunService")
function fling(player)
print(player) -- This also does too! no matter the command, it will print the player
local character = player.Character
if not character then return end
local hum = character:FindFirstChildWhichIsA("Humanoid")
if not hum then return end
local rp = hum.RootPart
local flingDirection = (CFrame.Angles(math.random() * math.pi + (math.pi / 2), math.random() * math.pi * 2, 0) * CFrame.new(1, 0, 0)).Position
local flingPower = 200
local rotatePower = 50
hum.Sit = true
hum:ChangeState(Enum.HumanoidStateType.Seated) -- preventative maintenance
local state, dead = hum:GetState(), false
local changed = Instance.new("BindableEvent")
local bodyVelocity = Instance.new("BodyVelocity")
local bodyAngularVelocity = Instance.new("BodyAngularVelocity")
local conc0, conc1 = hum.StateChanged:Connect(function()
state = hum:GetState()
changed:Fire()
end), hum.Died:Connect(function()
dead = true
changed:Fire()
end)
bodyVelocity.Velocity = flingDirection * flingPower
bodyAngularVelocity.AngularVelocity = flingDirection * rotatePower
bodyVelocity.Parent, bodyAngularVelocity.Parent = rp, rp
task.delay(0, function() -- For all intents and purposes, I'll run this thread synced with Heartbeat
while ((state == Enum.HumanoidStateType.Seated) and (not dead)) do changed.Event:Wait() end
conc0:Disconnect(); conc1:Disconnect()
changed:Destroy()
bodyVelocity:Destroy()
bodyAngularVelocity:Destroy()
end)
end
players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
msg = string.lower(msg)
msg = string.split(msg, " ")
if msg[1] == "/fling" then
print("fart") -- this prints fine!
if msg[2] ~= nil then
if msg[2] == "all" then
for _, player in pairs(players:GetPlayers()) do
fling(player)
end
elseif type(msg[2]) == "string" then
local MatchPlayer = nil
local MatchStart = math.huge
for _, CheckPlayer in pairs(players:GetPlayers()) do
local CheckStart = string.find(string.lower(CheckPlayer.Name), msg[2])
if CheckStart ~= nil and CheckStart < MatchStart then
MatchPlayer = CheckPlayer
MatchStart = CheckStart
end
end
if MatchPlayer then fling(MatchPlayer) end
end
else
fling(player)
end
end
end)
end)
You want to prevent the humanoid controller from applying its own custom physical influence by setting it to a state that is both user escapable (meaning the user can press some sort of input and escape the non-physic state) and disables humanoid physical influence.
You also didn’t parent the velocity instances to anything.
Ig you didn’t look at my other post I just posted on your other post lol. Here is the fixed script:
function fling(player)
print(player) -- This also does too! no matter the command, it will print the player
local character = player.Character
if not character or not character.PrimaryPart or not character.Humanoid then return end
local flingDirection = (CFrame.Angles(math.random() * math.pi + (math.pi / 2), math.random() * math.pi * 2, 0) * CFrame.new(1, 0, 0)).Position
local flingPower = 200
local rotatePower = 50
local bodyVelocity = Instance.new("BodyVelocity")
local bodyAngularVelocity = Instance.new("BodyAngularVelocity")
bodyVelocity.Parent = character.HumanoidRootPart
bodyAngularVelocity.Parent = character.HumanoidRootPart
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyAngularVelocity.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Velocity = flingDirection * flingPower
bodyAngularVelocity.AngularVelocity = flingDirection * rotatePower
game.Debris:AddItem(bodyVelocity, .15) --Adjust time as needed
game.Debris:AddItem(bodyAngularVelocity, .15) --Adjust time as needed
end
i thought i responded? ig i forgot to, but that didnt work. i like the sitting thing the other guy did, but that wont work. can you help us figure out why that wont work?
The maximum allowed torque/force is not the problem.
It works in his test place, and besides the default property for both is Vector3.one * 4000, so even if he didn’t set them, it would still apply a very noticeable force.
ok i tried it, now it pushes my over a little, maybe slams me into a wall (not the force i wanted) and after it, im just being constatly spun and pushed
Flings until player jumps out of the Seated state:
local players = game:GetService("Players")
local runService = game:GetService("RunService")
function fling(player)
print(player) -- This also does too! no matter the command, it will print the player
local character = player.Character
if not character then return end
local hum = character:FindFirstChildWhichIsA("Humanoid")
if not hum then return end
local rp = hum.RootPart
local flingDirection = (CFrame.Angles(math.random() * math.pi + (math.pi / 2), math.random() * math.pi * 2, 0) * CFrame.new(1, 0, 0)).Position
local flingPower = 200
local rotatePower = 50
hum.Sit = true
hum:ChangeState(Enum.HumanoidStateType.Seated) -- preventative maintenance
local state, dead = hum:GetState(), false
local changed = Instance.new("BindableEvent")
local bodyVelocity = Instance.new("BodyVelocity")
local bodyAngularVelocity = Instance.new("BodyAngularVelocity")
local conc0, conc1 = hum.StateChanged:Connect(function()
state = hum:GetState()
changed:Fire()
end), hum.Died:Connect(function()
dead = true
changed:Fire()
end)
bodyVelocity.Velocity = flingDirection * flingPower
bodyAngularVelocity.AngularVelocity = flingDirection * rotatePower
bodyVelocity.Parent, bodyAngularVelocity.Parent = rp, rp
task.delay(0, function() -- For all intents and purposes, I'll run this thread synced with Heartbeat
while ((state == Enum.HumanoidStateType.Seated) and (not dead)) do changed.Event:Wait() end
conc0:Disconnect(); conc1:Disconnect()
changed:Destroy()
bodyVelocity:Destroy()
bodyAngularVelocity:Destroy()
end)
end
players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
msg = string.lower(msg)
msg = string.split(msg, " ")
if msg[1] == "/fling" then
print("fart") -- this prints fine!
if msg[2] ~= nil then
if msg[2] == "all" then
for _, player in pairs(players:GetPlayers()) do
fling(player)
end
elseif type(msg[2]) == "string" then
local MatchPlayer = nil
local MatchStart = math.huge
for _, CheckPlayer in pairs(players:GetPlayers()) do
local CheckStart = string.find(string.lower(CheckPlayer.Name), msg[2])
if CheckStart ~= nil and CheckStart < MatchStart then
MatchPlayer = CheckPlayer
MatchStart = CheckStart
end
end
if MatchPlayer then fling(MatchPlayer) end
end
else
fling(player)
end
end
end)
end)
Flings until 0.1 sec duration elapsed.
local players = game:GetService("Players")
local runService = game:GetService("RunService")
function fling(player)
print(player) -- This also does too! no matter the command, it will print the player
local character = player.Character
if not character then return end
local hum = character:FindFirstChildWhichIsA("Humanoid")
if not hum then return end
local rp = hum.RootPart
local flingDirection = (CFrame.Angles(math.random() * math.pi + (math.pi / 2), math.random() * math.pi * 2, 0) * CFrame.new(1, 0, 0)).Position
local flingPower = 200
local rotatePower = 50
hum.Sit = true
hum:ChangeState(Enum.HumanoidStateType.Seated) -- preventative maintenance
local bodyVelocity = Instance.new("BodyVelocity")
local bodyAngularVelocity = Instance.new("BodyAngularVelocity")
bodyVelocity.Velocity = flingDirection * flingPower
bodyAngularVelocity.AngularVelocity = flingDirection * rotatePower
bodyVelocity.Parent, bodyAngularVelocity.Parent = rp, rp
task.delay(0.1, function() -- For all intents and purposes, I'll run this thread synced with Heartbeat
bodyVelocity:Destroy()
bodyAngularVelocity:Destroy()
end)
end
players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
msg = string.lower(msg)
msg = string.split(msg, " ")
if msg[1] == "/fling" then
print("fart") -- this prints fine!
if msg[2] ~= nil then
if msg[2] == "all" then
for _, player in pairs(players:GetPlayers()) do
fling(player)
end
elseif type(msg[2]) == "string" then
local MatchPlayer = nil
local MatchStart = math.huge
for _, CheckPlayer in pairs(players:GetPlayers()) do
local CheckStart = string.find(string.lower(CheckPlayer.Name), msg[2])
if CheckStart ~= nil and CheckStart < MatchStart then
MatchPlayer = CheckPlayer
MatchStart = CheckStart
end
end
if MatchPlayer then fling(MatchPlayer) end
end
else
fling(player)
end
end
end)
end)
When you do change the fling power variable, you want to make sure its in the bounds of MaxForce/MaxTorque. If you want to raise the ceiling of this, use what @Lifespzm did and add this bit above where the velocities are being changed.