Help sending information from client to server

I try copy and pasting my code but only half of it goes into a code box how do I fix do that?

Select the entire script then put it inside a code box, is your ctrl c and ctrl v not working?
If not then try to send a screenshot of the code

1 Like

this is whats happening

— local script

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

script.Parent.Parent.Activated:Connect(function()

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

local rayOrigin = script.Parent.Position

local raycastResult = workspace:Raycast(rayOrigin, mouse.UnitRay.Direction* 250 , raycastParams)

print(raycastResult)



script.Parent.Parent.Handle.FireSound:Play()

script.Parent.Parent.FireGun:FireServer(player, mouse.Hit.Position)

end)

—normal script

script.Parent.Parent.FireGun.OnServerEvent:Connect(function(player,mouse)
local MousePosition = mouse --Your mouse position from remote event
local origin = script.Parent.Position-- your origin

	local Direction = (MousePosition - origin).Unit
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent.Parent, player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local ray = workspace:RayCast(origin,Direction, raycastParams)



print("IS THIS")

end)

script.Parent.Parent.FireGun.OnServerEvent:Connect(function(player,mouse)
local MousePosition = mouse --Your mouse position from remote event
local origin = script.Parent.Position-- your origin

	local Direction = (MousePosition - origin).Unit
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent.Parent, player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local ray = workspace:RayCast(origin,Direction, raycastParams)

if ray then
  print("IS THIS")
end
end)
1 Like

Does it show any error? is it printing when the ray hits?

1 Like

It prints raycast because its being done on a local script

Print origin and print MousePosition, both of them need to be vector3 values

1 Like

So I did that in the local script




image

you need to print origin and MousePosition above the local Direction line

1 Like

so do you want me to make it the first line in the function?

I see what’s wrong now

Don’t include the player parameter in your :FireServer(), as the server’s OnServerEvent’s first parameter is default to whoever fired it

script.Parent.Parent.FireGun:FireServer(mouse.Hit.Position) --only send mouse.Hit.Position
1 Like

I did that now I get this

sending a player variable through the :FireServer() will be read like this in the .OnServerEvent

localscript

RemoteEvent:FireServer(--localplayer--,mouse.Hit.Position)

How its read in the .OnServerEvent

Remote.OnServerEvent:Connect(function(player,TheSamePlayer, TheActualPosition)

end)
1 Like

its Raycast
not RayCast,
small c

1 Like

alright ive done that now there is no errors. does that mean the server script has the final results of the raycast now? I cant tell because im not getting any server feedback in the output.

Try to print ray.Instance inside the if ray then statement, if it prints then it works

if ray then
  print(ray.Instance.Name)
end
1 Like

Im not getting any server feedback.

Its working, its just that the ray is only firing like 1 stud facing your mouse.Hit.Position. How to fix this?

Multiply the Direction by as many studs you want the raycast to go

local ray = workspace:Raycast(origin, Direction * 1000, raycastParams) -- Direction * 1000 = 1000 studs in the direction facing mouse.Hit.Position
1 Like

It worked! Thank you for this.

1 Like

I suggested this to the other thread you posted.