This is my first time making a cannon game its about giant cannons that you can carry.I used the script that made the classic rocketlauncher work but im not satisfied.Ive been making scripts for the gun but nothing seems to work on it have i made the gun scripts wrong can anyone show me a script?
A couple things you need, A local script A regular script A remote event
Local Script will get the Player's Mouse Position On Click Then it will fire the remote event
The regular script will pick up the remote event and send a ray in that direction.
RemoteEvent- well, sends the information from script to script. Since it seems you are new to programming, I can help.
-- LocalScript local tool = script.Parent local plr = game.Players.LocalPlayer local chr = plr.Character or plr.CharacterAdded:wait() local mouse = plr:GetMouse() local event = tool:WaitForChild("RemoteEvent") tool.Activated:Connect(function() event:FireServer(mouse.Hit.p) end)
Divider
-- Regular Script local tool = script.Parent local event = tool:WaitForChild("RemoteEvent") event.OnServerEvent:Connect(function(plr, info) local origin = tool:WaitForChild("Handle).Position local direction = (info - origin).Unit * 500 -- change 500 (range) local ourRay = Ray.new(origin, direction) local ignore = {plr.Character} local part, position, normal = workspace:FindPartOnRayWithIgnoreList(ourRay, ignore) local explosion = Instance.new("Explosion", workspace) if position then explosion.Visible = true explosion.BlastRadius = 20 explosion.Position = position end end)
Sorry if this doesn't work, I have not tested it, I just made it here, also sorry if its too little design I made it in a rush.