Hey. I'm trying to move character to clicked seat object. There is no specific seat object to move. The seat objects will generated by game so there is no object name it will be incrementing number or same name for all seats.
Of course filtering is enabled. How can i listen all clicks ? How can i get the info who clicked and which seat clicked (or just seat position) ? If i can get these informations i can easly use MoveTo function.
I couldn't build the logic i'm appreciated for every comment.
The easiest solution is this. Every time a new seat is made, have a script clone another script inside the seat. This script inside the seat will define a bindable event in ReplicatedStorage. Lets name this "SeatClicked". When the seat is clicked, make the script fire that event with 2 args; PlayerName, and seatName. Now make another script and put it in server storage. This script will detect when the event is fired. To do this, Put the following in:
Clicked = game:GetService("ReplicatedStorage"):WaitForChild("SeatClicked") Clicked.Event:Connect(function(plr, seat) local char = workspace:FindFirstChild(plr) char:MoveTo(workspace:FindFirstChild(seat).Position) end)
Thank you so much for your reply. I did some research about bindable events and i did something like this with your suggestion. I have seat object on workspace for testing and there is click detector child of seat. Lastly a script object child of click detector. Oh and of course bindable event on replicated storage called "DeskClicked". Here is a code of this script :
local clicked = game:GetService("ReplicatedStorage"):WaitForChild("DeskClicked") local clickDetector = script.Parent local seatPosition = script.Parent.Parent:FindFirstChild("Seat").Position clickDetector.MouseClick:Connect(function(player) print("Event Fired!") clicked:Fire(player,seatPosition) end)
and there is a listener script object on ServerStorage called HandleDeskClick here is the code :
local Clicked = game:GetService("ReplicatedStorage"):WaitForChild("DeskClicked") Clicked.Event:Connect(function(plr, seatPosition) local char = workspace:FindFirstChild(plr) char:MoveTo(seatPosition) print("Event Handled!") end)
I can see Event Fired! message on console but there is no Event Handled! message. And there is no error output too. Is there any mistake i made ? Thanks!