Problem with firing BindableEvent

( this is my first topic, im sorry if you see any mistakes )

  1. What do you want to achieve? I want to move a part with mouse position on a grid, but i ran into a problem on start doing that.

  2. What is the issue? I am using local script inside StarterPlayerScripts ( ill provide it below it lua code block ) which gets mouse position, prints it and fires it through bindable event, but when i try it, local script gives me an error

  3. What solutions have you tried so far? I looked on developer hub for solutions, but didnt find anything, i tried to use common Script instead of LocalScript

I am not really experienced in scripting, so the problem would sound very stupid :frowning:

LocalScript:

local Players = game:GetService("Players")


local player = Players.LocalPlayer


local mouse = player:GetMouse()


local function onMouseMove()

	print("mouse screen position: ", mouse.X, mouse.Y)

	local PlE = game:GetService("ServerScriptService"):FindFirstChild("PlacementEvent")

	local positionX = mouse.X
	local positionY = mouse.Y

	PlE:Fire(positionX, positionY)
end

mouse.Move:Connect(onMouseMove)

Script:

local PlE = game:GetService("ServerScriptService"):FindFirstChild("PlacementEvent")

PlE.Event:Connect(function(positionX, positionY)
	print("X POS:", positionX)
	print("Y POS:", positionY)
end)

BindableEvents are for Server → Server or Client → Client communication. What you are looking for is a RemoteEvent. RemoteEvent uses :FireClient(player), .OnClientEvent(), :FireServer(), and .OnServerEvent(). You also can’t access ServerScriptService from the Client(localscript).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.