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

How do you get the Mouse.Hit.P in a script when it is stored in ServerScriptService?

Asked by 6 years ago
Edited 6 years ago

local repstore = game:WaitForChild("ReplicatedStorage") local Remote = repstore:WaitForChild("SmokeFlyStart")

Remote.OnServerEvent:Connect(function(player)

local char = player.Character

    for i, v in pairs (char:GetChildren()) do
        if  v.ClassName == "Part" or v.ClassName == "MeshPart" then
            v.Transparency = 1
            end     
    end
    local Smoke = game.Lighting.Smoke:Clone()
    Smoke.Parent = char.HumanoidRootPart
    local BV = Instance.new("BodyVelocity",char.HumanoidRootPart)
    BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    for i = 1,200 do 
        wait()
        char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position,***Mouse.Hit.p***)
        BV.Velocity = char.HumanoidRootPart.CFrame.lookVector*90
    end
    for i, v in pairs (char:GetChildren()) do
            if v.ClassName == "Part" or v.ClassName == "MeshPart" then
                if v.Name ~= "HumanoidRootPart" then 
                 v.Transparency = 0 
            end
        end
    Smoke:Destroy() 
    BV:Destroy()
    end

end)

I'm fairly new to scripting and this has been giving problem. Not sure if I'm suppose to create more variables. Is there a way to read the Mouse.Hit.p and transfer somehow?

0
even though this causes a bit of latency, you should probably use remote events theking48989987 2147 — 6y
0
^ and really, no need to WaitForChild on a service. That's stupid and they will exist. And don't use Lighting as storage, that is not what it's for. User#24403 69 — 6y
0
yes. TheluaBanana 946 — 6y
0
Thats not really answer my question. Kronidex 9 — 6y
View all comments (2 more)
0
So what? I'm just giving tips so you can be a better coder. User#24403 69 — 6y
0
Didn't meant that personally. Kronidex 9 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

u can t rly get mouse.Hit.p from a script; that has to be done locally(from a localscript) and transferred to a script. I recommend u get a localscript in all players and transfer the mouse.Hit.p via a remote event to the said script

what well do now is place a localscript in a script in the serverscriptservice to be cloned to all players

in script:

local item = script.LocalScript

local re = Instance.new("RemoteEvent", game.ReplicatedStorage)
re.Name = "mouse_event"

game.Players.PlayerAdded:connect(function(player)
    local clone = item:Clone()
    clone.Parent = player:WaitForChild("Backpack")
    clone.Disabled = false

    wait(1)

    re:FireClient(player)
end)

re.OnServerEvent:connect(function(player, mpos)
    print(mpos)
end)

in localscript:

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

local repstore = game.ReplicatedStorage

local re = repstore:FindFirstChild("mouse_event") or repstore:WaitForChild("moues_event")

re.OnClientEvent:connect(function()
    re:FireServer(mouse.Hit.p)
end)

make sure the localscript is disabled; this will print out the player's mouse.Hit.p in approx. 1 second after a player has loaded in.

0
connect is deprecated, use Connect. p is deprecated as well so use Position, and why are you cloning scripts everywhere? You don't need to do that. User#24403 69 — 6y
Ad

Answer this question