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

How to seat a player via module script?

Hello! I am beginning to learn about Module Scripts. Right now, I am using a local script to detect when the player clicks a seat to fire a function in a module script which seats the player in the seat. My problem is that I do not know how to make the player sit in the clicked seat. Right now on line four of my module script, I have it addressing a specific seat in the workspace whereas it would be ideal so that the player would sit in any clicked seat without needing to do game.Workspace.Model.Seat . How would I change line four?

Local Script:

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()

local testFunctions = require(game.ReplicatedStorage:WaitForChild("ModuleScript"))

mouse.Button1Down:Connect(function()
	if mouse.Target and mouse.Target.Parent and (game.Workspace[player.Name].HumanoidRootPart.Position - mouse.Target.Position).magnitude < 8 then
		testFunctions.Clicked(player,mouse.Target.Name)
	end
end)

Module Script:

local testFunctions = {}

function testFunctions.Clicked(plr, partName)
	game.Workspace.Model[partName].Seat:Sit(game.Workspace[plr.Name].Humanoid)
end

return testFunctions

1 answer

✓ Accepted answer

Instead of passing the name of the part as the second argument, just pass the instance itself (remove .Name). Then you can do:

local testFunctions = {}

function testFunctions.Clicked(plr, seat) -- seat is the instance
	seat:Sit(workspace[plr.Name].Humanoid)
end

return testFunctions

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