|
| 23 Aug 2016 08:41 PM |
So basically what my script does is when you click the key `, it shoots a brick called "FirebBall" at the location of the players Mouse. The problem is that whenever my mouse is hovering over a brick and sometime terrain, it gives faulty mouse location readings so instead of shooting at the brick or terrain, it shoots to the side of it. Here's my scripts, hopefully I can get a solution. If you have the time to test this out yourself, pay attention to the printed coordinates of the mouse. You'll notice a huge jump of hundreds if not thousands when moving the mouse from right above a brick, to on a brick.
Following is a local script in a textbutton which is located in the players PlayerGuis.
local contextActionService = game:GetService("ContextActionService")
Move = script.Parent
function onKeyPress(actionName, userInputState, inputObject) plr = game.Players.LocalPlayer local mouse = plr:GetMouse() if userInputState == Enum.UserInputState.Begin then MouseLocation = (mouse.Hit.p) print (MouseLocation) print ("Localscript Mouse^^^") game.Workspace.MyMovesRemoteFunction:InvokeServer({"FireBall", MouseLocation}) end end game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.Backquote)
--------------------
Next is a ServerScript located in Workspace.
local myRemoteFunction = Instance.new("RemoteFunction") myRemoteFunction.Parent = game.Workspace myRemoteFunction.Name = "MyMovesRemoteFunction" function myRemoteFunction.OnServerInvoke(player,message) print (player.Name) print (message[1]) print (message[2]) print ("Mouse^^") if message[1] == ("FireBall") then print ("Is FireBall") plr = game.Players:WaitForChild(player.Name) FireBall = Instance.new("Part") FireBall.Shape = ("Ball") FireBall.FormFactor = 3 FireBall.Size = Vector3.new(1, 1, 1) FireBall.Parent = game.Workspace FireBall.CanCollide = true FireBall.Anchored = false FireBall.Name = ("FireBall") FireBall.BrickColor = BrickColor.new("Bright red")
Fire = Instance.new("Fire") Fire.Parent = FireBall FireBall.CFrame = CFrame.new(plr.Character.Torso.Position) print (FireBall.CFrame) print (message[2]) print ("Mouse2^^") direction = (message[2]).unit spawnPos = plr.Character.Torso.Position + direction * 2.0 FireBall.Velocity = direction * 100.0 FireBall.RotVelocity = Vector3.new(0, 10, 0) local floatForce = Instance.new("BodyForce") floatForce.force = Vector3.new(0, FireBall:GetMass() * 196.1, 0) floatForce.Parent = FireBall delay(5,function() floatForce:Destroy() end) print ("FireBall creation complete") end end
|
|
|
| Report Abuse |
|
|
|
| 23 Aug 2016 09:29 PM |
dont use keydown use userinputservice
much better for handling commends on a key press |
|
|
| Report Abuse |
|
|
| |
|
| |
|
Mitko0o1
|
  |
| Joined: 30 Nov 2010 |
| Total Posts: 5725 |
|
|
| 24 Aug 2016 07:29 AM |
Open the output and paste the error, lookinf for script mistages in a large code is like finding a needle in a haystack.
am triggered |
|
|
| Report Abuse |
|
|
thatkidog
|
  |
| Joined: 17 Aug 2006 |
| Total Posts: 14 |
|
|
| 24 Aug 2016 07:44 AM |
make local plr = game:GetService("Players").LocalPlayer
Also this script is much like a laser script which roblox has a tutorial with using RayCasting,
Here it is http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun
|
|
|
| Report Abuse |
|
|
|
| 24 Aug 2016 08:27 AM |
| There are no errors. The only thing worth seeing in the output os the print of the mouse location which jumos by thousands when over a brick or terrain. |
|
|
| Report Abuse |
|
|
|
| 24 Aug 2016 08:30 AM |
Youtube video (guess you can't show output but just try my scripts if you want to try and help solve the issue.) - https://www.youtube.com/edit?video_id=3lf2ASALP-8
|
|
|
| Report Abuse |
|
|
|
| 24 Aug 2016 05:12 PM |
| Correct youtube link - https://www.youtube.com/watch?v=3lf2ASALP-8 |
|
|
| Report Abuse |
|
|