Issue with function(plr, mousePos)

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Set a npc position to the mouse position.

  2. What is the issue? Include screenshots / videos if possible!
    The player name is show instead of the mouse position

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    –Watched tutorial
    –Looked solution on Developer Hub

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

The tool:
image

MousePos script:

local tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()

local Remote1 = tool.Spawn_Boner

tool.Activated:Connect(function()
	local mousePos = mouse.Hit.Position
	print(mousePos)
	if script.Parent.Selected.Value == 1 then
		Remote1:FireServer(plr, mousePos)
	end
end)

Spawning script:

local tool = script.Parent

local Remote1 = tool.Spawn_Boner

Remote1.OnServerEvent:Connect(function(plr, mousePos)
	local clone = game.ReplicatedStorage.Halloween_Event_2022.Ennemy.Boner:Clone()
	clone.Parent = workspace
	
	print(mousePos)
	clone.HumanoidRootPart.Position = mousePos
end)

Output of the MousePos script:
image

Output of the Spawn script:
image

For some reason, the value seem to be changing from the mouse position (X,Y,Z) to an instance (game.Players.LocalPlayer)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

its because when you recieve the remote event, the plr variable will be transferred automatically. therefore there is no need to add plr in the local script/mousepos script

1 Like