Problem with RemoteEvent

I’m working on a script where the player can click on a part and the server will delete that part if the player clicks on the part long enough (kinda like Minecraft of other building games). I used Raycasting to get the part instance and a RemoteEvent to send the instance to the server, but when I put print statements into both the server and client, they print different names. Is there anything that I’m missing or being dumb about?

LocalScript

local tool = script.Parent
local destroy = game.ReplicatedStorage:WaitForChild("Destroy")
local player = game.Players.LocalPlayer
local character = game.Workspace:WaitForChild(player.name, 5)
local mouse = player:GetMouse()
local Workspace = game.Workspace
local pos

local function toolEquipped()
	if character then
		tool.Activated:Connect(function()
			local mousepos = mouse.Hit.Position
			local direction = (mousepos - character.PrimaryPart.Position).Unit * 20
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {character}
			local result = Workspace:Raycast(character.PrimaryPart.Position, direction, raycastParams)
			if result then
				print(result.Instance.Name)
				destroy:FireServer(result.Instance)
			end
			wait(0.5)
			if mouse.Button1Up then
				return
			end
		end)
	end
end
tool.Equipped:Connect(toolEquipped)

ServerScript

local destroy = game.ReplicatedStorage:WaitForChild("Destroy")

destroy.OnServerEvent:Connect(function(part)
	print(part)
end)

The first argument of the OnServerEvent event’s function will always be the player who fired the remote event. Replace your script’s code with this:

local destroy = game.ReplicatedStorage:WaitForChild("Destroy")

destroy.OnServerEvent:Connect(function(player, part)
	print(part)
end)
1 Like