Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Anyways to grab "GetMouse()" from local script to server script?

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.

1 comment

0

Hello, I have replied to your comment. Check my answer to see the reply. Thanks.

2 answers

✓ Accepted answer

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.

  • AlessandroG200

2 comments

0

For the "Script" segment, I don't think you can just use hit.lookvector. hit has to come after Mouse as it's a property of "Mouse", so it's mouse.hit.lookvector.

0

The "mouse" cannot be passed to the server as only the client can see it and obtain it(Homewer, we can get the "Hit" property in the mouse in the client, and pass it's value to the server). Try looking this page: http://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events#Limitations

GetMouse() can only be called from a client (Local Script). Use remote events.

4 comments

0

Yup that's what i did. "FireballRemote" is my remote event. As described in my post I've tried to send the GetMouse() data from my local script to my server script using remote event, but to no avail. When the GetMouse() data reaches the server script, it became "nil" :/

0

You just can't get the mouse of a player on a server script.. (I'm scripting a projectile too c:)

0

Ahh nice. mm so you're saying the only way is to do the velocity adjustments locally? man that sucked :/

0

I know man.. :/

This discussion is preserved as it was. New answers, comments, and votes are closed.