So ive created this function that if a player uses the Proximityprompt, they get loaded into a cannon and get shot. Before i had it that when u touched a part then u would get shot this worked fine.
However now i tried replacing it with a proximityprompt and the code stops running somehow. Ive added a print where the codes stop running but i couldnt find the mistake. maybe someone can find the mistake that i cant see?
local cannon = script.Parent.ProximityPrompt
local touched = false
cannon.Triggered:Connect(function(touch)
local char = touch.Parent
if game.Players:GetPlayerFromCharacter(char) and char:FindFirstChild("HumanoidRootPart") and touched == false and not char:FindFirstChild("HumanoidRootPart"):FindFirstChild("BodyVelocity") then
print("Doesnt print this so mistake should be in the above line ^^")
char.HumanoidRootPart.CFrame = script.Parent.Parent.Tele.CFrame
touched = true
wait(0.5)
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(0,200,150)
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.P = math.huge
bodyVelocity.Parent = char.HumanoidRootPart
wait(1)
touched = false
bodyVelocity:Destroy()
end
end)