Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Click To Move Seat ?

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.

2 answers

✓ Accepted answer

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)

1 comment

0

I couldn't reply your message with detailed explanation so i send it as a answer. Can you check my code please :(

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!

3 comments

0

Only one problem I can see, is your firing to the same position every time because its predefined in the server. That means if the seats ever move, your screwed. To fix this simple error, just cut out the ".position" in line 5 and replace line 13 with "clicked:Fire(player, seatPosition.Position)

0

Thanks for the info. I found the real problem i guess. When i moved HandleDeskClick script from ServerStorage to ServerScriptService it's worked! Thanks for your help i'm really appreciated!

0

No problem, happy to help.

This discussion is preserved as it was. New answers, comments, and votes are closed.