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

How would a get position of mouse when using in serverscriptservice?

Asked by 5 years ago

I am using a Remote Event and calling from local script.

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

Player = game.Players.LocalPlayer Mouse = Player:GetMouse()

cool = true

Mouse.KeyDown:Connect(function(key)

key = key:lower()
if key == "r" then if cool ~= true then return end cool = false

 Remote:FireServer(Mouse.Hit.p)

wait(5)
cool = true

end

end)

PROBLEM IN SCRIPT

for i = 1,200 do 
        wait()
        char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position,HOW WOULD I GET MOUSE.HIT.P in this script)
        BV.Velocity = char.HumanoidRootPart.CFrame.lookVector*60
    end

2 answers

Log in to vote
0
Answered by 5 years ago

You fired the server with the right value you just never actually make a function serverside to "intercept" it.

Before I start you should not be using mouse.KeyDown as it is deprecated, heres a useful guide on how to use the 2 new methods.

Local

local repstore = game:WaitForChild("ReplicatedStorage") 
local Remote = repstore:WaitForChild("SmokeFlyStart")
Player = game.Players.LocalPlayer Mouse = Player:GetMouse()
cool = true
Mouse.KeyDown:Connect(function(key)
    key = key:lower()
    if key == "r" then if cool ~= true then return end cool = false
        Remote:FireServer(Mouse.Hit.p)
    wait(5)
    cool = true
    end
end)

We are going to use a thing called "OnServerEvent"

Server

game:WaitForChild("ReplicatedStorage"):WaitForChild("SmokeFlyStart").OnServerEvent:Conncet(function(mouseval)
for i = 1,200 do
        wait()
        char.HumanoidRootPart.CFrame = CFrame.new(mouseval.X,mouseval.Y,mouseval.Z)
        BV.Velocity = char.HumanoidRootPart.CFrame.lookVector*60
    end
end)
0
The problem with your script is that if youre trying to rotate the player to where the mouse is pointing, then in the entire for loop, the character will only rotate once and look in the same direction, because the Mouse position was sent only once, and isn't being updated as you move it serverside. The best way to rotate the character's torso to where the mouse is would be through a local script. ScrubSadmir 200 — 5y
0
This is the entire script Kronidex 9 — 5y
Ad
Log in to vote
0
Answered by 5 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(mouseval.X,mouseval.Y,mouseval.Z)
        BV.Velocity = char.HumanoidRootPart.CFrame.lookVector*60
    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)

using mouseval I got this error ServerScriptService.SmokeFly:23: attempt to index global 'mouseval'(a nil value)

0
The error means that the mouseval is not being detected and it does not have any value. Your problem is that you didn't define mouseval. To fix this just put a comma after player in line 4, and write mouseval. The value of mouse Val is now the mouses position, bc when the server fired, you passed arguments with the mouses position ScrubSadmir 200 — 5y

Answer this question