How can I make a cannon that shoots players when they touch?

Hello, I want to create a cannon that shoots out players when they touch them.
I have created a script, but I don’t know how to make the people launch from the cannon.
Thank you.

local part = script.Parent
local players = game.Workspace.Players

if players.Touched.part then
--and I don't know what to do here.
3 Likes

Use BodyForce

local part = script.Parent
local players = game.Workspace.Players

part.Touched:Connect(funciton(hit()
	local plr = players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		local bodyforce = Instance.new("BodyForce", plr.Character.HumanoidRootPart)
		bodyforce.Force = Vector3.new(2500,4500,-2500)
		plr.Character.HumanoidRootPart.Velocity = Vector3.new(200)
	end
end)

I think this is what you meant. Tell me if im wrong lol

2 Likes

Thanks, I will check the script out and test it; I’m not use to scripting BodyForces. :sweat_smile:

I tested it out, but it seems it’s not working.

Do I need to add a BodyForce to the part, or TouchInterest?

try adding platform stand, I’m not sure if it was an important part of my script or not when I used it :sweat_smile:

local part = script.Parent
local players = game.Workspace.Players

part.Touched:Connect(funciton(hit)
	local plr = players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.Character.Humanoid.PlatformStand = true
		local bodyforce = Instance.new("BodyForce", plr.Character.HumanoidRootPart)
		bodyforce.Force = Vector3.new(2500,4500,-2500)
		plr.Character.HumanoidRootPart.Velocity = Vector3.new(200)
	end
end)
1 Like

There is error saying that the local needs a bracket.
Here is the picture of it:
3

it doesnt work because he spelled function wrong, its function not funciton

1 Like

I fixed the spelling, but it still doesn’t work.

Do I have to add BodyForce to the part?

no, the script is compleatly wrong, game.Workspace.Players doesn’t exist. Replace it with game.Players

1 Like

There is another error.
Here is the picture:
5
Also I found a free model that can show you what I want to make.
This is the video:
robloxapp-20210611-2223142.wmv (2.0 MB)

firstly when player touch you have to make the player go in the cannon then make the player state to Ragdoll then ApplyImpulse to the HumanoidRootPart

1 Like

Ok, but I don’t know how to make the players launch.

local part = script.Parent
local players = game.Players

part.Touched:Connect(function(hit)
	local plr = players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.Character.Humanoid.PlatformStand = true
		local bodyforce = Instance.new("BodyForce", plr.Character.HumanoidRootPart)
		bodyforce.Force = Vector3.new(2500,4500,-2500)
		plr.Character.HumanoidRootPart.Velocity = Vector3.new(200)
	end
end)

try this in the second variable you said game.Workspace.Players thats wrong

1 Like

Try this

local part = script.Parent

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			hit.Parent.Humanoid.Sit = true
			local bodyforce = Instance.new("BodyForce", player.Character.HumanoidRootPart)
			bodyforce.Force = Vector3.new(2000, 500, -part.CFrame.LookVector * 5000)
		end
	end
end)
1 Like

or you could try this

local part = script.Parent
local cannonCFrame = yourCannonCFrame
part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			hit.Parent.Humanoid:ChangeState(1)
			hit.Parent:FindFirstChild("HumanoidRootPart").CFrame=cannonCFrame 
            hit.Parent:FindFirstChild("HumanoidRootPart"):ApplyImpulse(Vector3.new(0,3000,3000))
		end
	end
end)

not sure if it work cuz i wrote it in my phone and never tested it

1 Like

For “YourCanonCFrame”, do I have to do CFrame.“my part”? Thanks.

yes change that value to the CfRame of where you player shoudl be in the cannon

also make sure its cancollide of the cannon is true

1 Like

Sorry, but do I do CFrame.Vector3.new(50, 50, 50)? (I’m not use to scripting. :sweat_smile:)