Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i found the pos of my mouse in a normal script ?

Asked by 5 years ago

So , i'm making a move in a Roblox Name who is activated when you press the "C" Key . This move launch Ball very fast . Its like a fireball . The thing is that i dont know how to launch the fireball in the direction of my mouse , where my mouse is aiming .I know that i need to transfer value of the localscript with the remote but i tried with Mouse.Hit.p and it say nil value in the normal script so i dont kow how to fix that :c If u know answer me :) Thx

0
what about transfering the player:GetMouse(), try that maybe starmaq 1290 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

make a remote function in server script service --make sure its a function for this example well call it "MouseData"

this will be in a server script

local plr = --player that you want data from
local MouseX,MouseY = game.ReplicatedStorage.MouseData:InvokeClient(plr)

in a local script

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

game.ReplicatedStorage.MouseData.OnClientEvent:Connect(function()
    return mouse.X,mouse.Y
end)
0
yeah the normal scripts can't see local data like mouse or something WyattagumsBackUp 5 — 5y
0
Wrong method to call the client; it's `FireClient`. TheeDeathCaster 2368 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

So, I actually have a basketball that uses a similar function to what you're talking about. Let me show you through the code that I have.

--LocalScript
local UIS = game:GetService("UserInputService") - get the UIS
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("Fireball")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character

repeat wait() until Character -- Helps to find Player's Character

local Humanoid = Character:WaitForChild("Humanoid") --Find Humanoid

UIS.InputBegan:Connect(function(input, gameProcessed)
    if not gameProcessed then --Basically if they not typing
        if input.KeyCode == Enum.Keycode.C then
            Event:FireServer(humanoid, Mouse.Hit.p)
        end
    end
end)

Basically what I'm doing here is firing the humanoid to the server in order to get TargetPoint.

--Server Script
local RS = game:GetService("ReplicatedStorage")
local Event = RS:WaitForChild("Fireball")

local Debounce = true --Make sure it doesn't fire the fireball super fast all the time

Event.OnServerEvent:Connect(function(Player, Humanoid, Position)
    if Player and Humanoid and Position and Humanoid.Parent and game.Players:GetPlayerFromCharacter(Humanoid.Parent) == Player then
        if Debounce == true then
            Debounce = false
            Humanoid.TargetPoint = Position
            --Do Stuff (Basically make the fireball go to that position)
            FireballPart.Position = Position
            wait(2)
            Debounce = true
        end
    end
end)

I don't know if this works entirely, but I did implement it to the best of my abilities. Anybody else can help me lol.

Answer this question