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

How do you transfer the mouse position to a server script service?

Asked by 5 years ago

This is the local script

local repstore = game:WaitForChild("ReplicatedStorage") local Remote = repstore:WaitForChild("SmokeFlyStart") Player = game.Players.LocalPlayer Mouse = Player:GetMouse() UIS= game:GetService("UserInputService")

UIS.InputBegan:Connect(function(Input)
        if Input.KeyCode == Enum.KeyCode.R then
      Remote:FireServer(Mouse.Hit.p)
        wait(5)
   end  

end)

This is a flying script I'm trying to make 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(I NEED HELP HERE) 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)

Where it says "I NEED HELP HERE", I can't seem to get the Mouse.Hit.p I've tried mouseval.X,mouseval.Y,mouseval.Z doesn't work Its not local script so Mouse.Hit.p I passed it through the fireserver I just don't know where to go from there.

0
try using a module script supercoolboy8804 114 — 5y
0
fix your lua brackets DinozCreates 1070 — 5y
0
Yeah, it makes it kind of confusing to look at. Knineteen19 307 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

To send the mouse position to the server, in your local script where you say :FireServer(), in the parentheses put the mouses position with something like Mouse.Hit.Position, if you have a variable named Mouse. Now in your server script, in the parameters after player for the on server event, after player, make a argument for the mouse position, and name it whatever you want, like mousep. Just know I did this on mobile lol. I also recommend not using lighting as storage. Use server storage for server scripts or replicated storage.

Your server script:

repstore = game:WaitForChild("ReplicatedStorage") 
local Remote = repstore:WaitForChild("SmokeFlyStart") Remote.OnServerEvent:Connect(function(player,mousep)

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") 
BV.Parent = char.HumanoidRootPart
BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) for i = 1,200 do 
wait()
char.HumanoidRootPart.CFrame = CFrame.new(mousep.X,mousep.Y,mousep.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)

If this script gets an error, it could be because of trying to set a CFrame using Vector3 values. If this is the case, then change Mouse.Hit.p in the local script where you fire the server to Mouse.Hit, which is the mouses CFrame.

Ad

Answer this question