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.
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
try adding platform stand, I’m not sure if it was an important part of my script or not when I used it
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)
There is another error.
Here is the picture:
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)
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
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)
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