Problem while moving blocks through a remote event

I want to make some sort of a telekinesis power , so i slapped in a local script,a server script and a remote and got to work, then i faced a problem, the remote was indeed firing but the server script wasnt recieving it.
Can you help me out?

The script:

local remote = script.Parent.Parent.RemoteEvent

remote.OnServerEvent:Connect(function(player, mousepos)
	print("recieved")
	local params = RaycastParams.new()
	params.FilterDescendantsInstances(player.Character)
	params.FilterType = Enum.RaycastFilterType.Blacklist
	local ray = workspace:Raycast(player.Character.Head.Position, (mousepos - player.Head.Position) * 300,params)
	if ray then
		local part = ray.Instance
		part.Position = mousepos
	end
end)

i tried everything at this point and i want to keep my sanity intact

1 Like

Since I’m not aware of any RemoteEvent bugs at the moment, if “recieved” is not printing then it means:

  • Your remote is not firing;
  • You are firing/receiving data from the wrong remote.

The remote is indeed firing since i made it print something when it does, the main problem is that the server script isnt recieving it.

So far there is only a single remote wich is the one stated in the script.

Would you mind giving the LocalScript, ServerScript, and RemoteEvent explorer locations?

Local Script:

local UIS = game:GetService("UserInputService")
local remote = game:GetService("ReplicatedStorage").RemoteEvent
local mouse = game.Players.LocalPlayer:GetMouse()
local mousepos = mouse.Hit.Position
UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		remote:FireServer(mousepos)
		print("fired")
	end
end)

Server Script:

local remote = script.Parent.Parent.RemoteEvent

remote.OnServerEvent:Connect(function(player, mousepos)
	print("recieved")
	local params = RaycastParams.new()
	params.FilterDescendantsInstances(player.Character)
	params.FilterType = Enum.RaycastFilterType.Blacklist
	local ray = workspace:Raycast(player.Character.Head.Position, (mousepos - player.Head.Position) * 300,params)
	if ray then
		local part = ray.Instance
		part.Position = mousepos
	end
end)

And the screenshot of the explorer locations:
pls help

Scripts won’t run in ServerStorage or ReplicatedStorage. Move the ServerScript to ServerScriptService

You have the mousePos stored, try changing it before firing the remote.

Now it’s recieving but there’s another error, the error states “attempt to call a table value” on line 6 of the server script, i tried tweaking it and it still doesn’t work

params.FilterDescendantsInstances = {player.Character}

I don’t see the problem tough, i used that on other scripts before and it used to work

Not sure why it would work since FilterDescendantsInstances requires a table type parameter.

Oh wait, i just realized what i did wrong.

Now there’s a different problem entirely, the script itself works but instead of moving the test part i have directly infront of me, it moves the spawnlocation

I added some exceptions to not move the Baseplate nor the SpawnLocation and the script doesnt even work now.
It seems like for some reason, the raycast isnt detecting the part infront of me.

(mousepos - player.Head.Position) * 300

This isn’t even valid, ‘Head’ isn’t a child of player instances.

(mousepos - player.Character.Head.Position).Unit * 300

You should be checking the console for errors so that you can debug yourself.

i tried it, didnt work.

for some reason, the ray is casted, recieved but the test block doesnt move.

i debugged it, apparently the ray is going backwards, weird

local part = ray.Instance
part.Position = mousepos

You need to filter the part instance before setting its position.

mouse.TargetFilter = part

https://developer.roblox.com/en-us/api-reference/property/Mouse/TargetFilter