Help with flinging players

I’m currently trying to have all of the players in a server get flung (except the buyer) when a player purchases a specific developer product. I’ve tried all of the ways I can think of implementing this with no luck.

This is the code I’ve been working with. It’s in a script with all of my other developer products (which all work luckily). Any ideas on how to implement this?

-- productFunctions[productnumber] = function(receipt, player)
	local forceNum = {100000,100000,100000}
	local bodyForce = Instance.new("BodyForce")
	bodyForce.Force = Vector3.new(0,forceNum[1],0)
	
	local rootPart = Players.LocalPlayer.HumanoidRootPart
	bodyForce.Parent = rootPart
	
end
 

Have you tried to use VectorForce instead?

See you’re getting the Humanoid Root Part from inside the PLAYER, not the character. To do this you have to change

local rootPart = Players.LocalPlayer.HumanoidRootPart

to

local char = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
local rootPart = char:WaitForChild("HumanoidRootPart")
1 Like

I have with no luck

I’ve tried this however when purchasing the developer product nothing happens. Not getting any errors, just no flinging.

-- productFunctions[productnumber] = function(receipt, player)
local purchaserName = player.Name
for i, v in pairs(players:GetChildren()) do
	if v.Name ~= purchaserName then
		local character = v:WaitForChild("Character")
		local HRP = character:WaitForChild("HumanoidRootPart")
		local forceNum = 100000
		local bodyForce = Instance.new("BodyForce")
		bodyForce.Force = Vector3.new(0,forceNum,0)
		bodyForce.Parent = HRP
	end
end

I haven’t tested your body force instance to see if it does what you require but this script will cycle through the HumanoidRootPart instances of each player (except the player who purchased the product).

This works for affecting everyone except the purchaser. Now just need to figure out how to actually have players get flung. Which ever way I try, the entire script breaks and the other dev products stop working as well.

https://developer.roblox.com/en-us/api-reference/function/Humanoid/ChangeState

Have you tried changing the character’s humanoid state to “Ragdoll”?

-- productFunctions[productnumber] = function(receipt, player)
local purchaserName = player.Name
for i, v in pairs(players:GetChildren()) do
	if v.Name ~= purchaserName then
		local character = v:WaitForChild("Character")
		local humanoid = character:WaitForChild("Humanoid")
		humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	end
end

I’m pretty sure that the MarketplaceService doesn’t work in a LocalScript.

Character is a PROPERTY of the player, NOT a model. You can’t use WaitForChild on a model which is why we have this special thing for looking for the character:

local character = v.Character or v.CharacterAdded:Wait()

I meant to use :GetAttribute, thanks for picking up on that.

-- productFunctions[productnumber] = function(receipt, player)
local purchaserName = player.Name
for i, v in pairs(players:GetChildren()) do
	if v.Name ~= purchaserName then
		local character = v:GetAttribute("Character")
		local humanoid = character:WaitForChild("Humanoid")
		humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	end
end

MarketplaceService does work in local scripts.

1 Like

The problem is most likely that it is locally flinging the player who bought it, instead of handling it on the server. Also, I advise against doing this on the client, who with the right exploits, can run this over and over.