Hi guys, I'm testing a "hack proof" fireball. I'm having trouble at the point of trying to grab GetMouse() from my local script, and pass it to my serverscript, since GetMouse() can only be used by LocalScripts. Here's my scripts:
Local
RS = game:GetService("ReplicatedStorage") --Where I store my remotes (kinda unsafe?) --declaring shortcuts-- fireball = script.Parent player = game.Players.LocalPlayer fireballremote = RS:FindFirstChild("FireballRemote") mouse = player:GetMouse() --mousepos = mouse.hit clickdebounce = false fireball.Activated:connect(function() if clickdebounce == false then clickdebounce = true --local character = player.Character fireballremote:FireServer(mouse) wait(0.5) clickdebounce = false end end)
Server
RS = game:GetService("ReplicatedStorage") --declaring shortcuts-- fireballremote = RS:FindFirstChild("FireballRemote") fireballremote.OnServerEvent:connect(function(...) --Receiving and setting up data-- local Tuple = {...} local player = Tuple[1] local character = player.Character local mouse = Tuple[2] local projectile = character.FireBall.Handle:Clone() --Setting up projectile-- local bv = Instance.new("BodyVelocity",projectile) bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge) bv.Velocity = mouse.hit.lookVector * 50 projectile.Parent = game.Workspace
The problem with doing this is the variable "mouse" inside of the server script will always receive a value of "nil" upon entering the "OnServerEvent". I've also tried saving "Mouse.hit" and pass it to the server, but doing so it seems to cause the position of the firing projectile to be fixed regardless of where i point my mouse and click. The problem will probably be solved if I'm able to move the "--Setting up projectile--" to the local script, but i do not want hackers to edit my values.
Well, I think that the solution to this is pass the "mouse.hit" instead:
Result:
LocalScript:
RS = game:GetService("ReplicatedStorage") --Where I store my remotes (kinda unsafe?) --declaring shortcuts-- fireball = script.Parent player = game.Players.LocalPlayer fireballremote = RS:FindFirstChild("FireballRemote") mouse = player:GetMouse() -- mousepos = mouse.hit clickdebounce = false fireball.Activated:connect(function() if clickdebounce == false then clickdebounce = true --local character = player.Character fireballremote:FireServer(mouse.Hit) -- Here is the fix wait(0.5) clickdebounce = false end end)
Script:
RS = game:GetService("ReplicatedStorage") --declaring shortcuts-- fireballremote = RS:FindFirstChild("FireballRemote") fireballremote.OnServerEvent:connect(function(...) --Receiving and setting up data-- local Tuple = {...} local player = Tuple[1] local character = player.Character local hit = Tuple[2] local projectile = character.FireBall.Handle:Clone() --Setting up projectile-- local bv = Instance.new("BodyVelocity",projectile) bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge) bv.Velocity = hit.lookVector * 50 -- Second fix projectile.Parent = game.Workspace end
Hope that helps.
GetMouse() can only be called from a client (Local Script). Use remote events.