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

How can I make the Selection service work in this case? (Plugin)

local PluginManagerObject = PluginManager()
local Plugin = PluginManagerObject:CreatePlugin()
local Toolbar = Plugin:CreateToolbar("Seat to Part Plugin")
local Button = Toolbar:CreateButton("Seat > Part","Transform a seat to a part in just a few clicks!","http://www.roblox.com/asset/?id=516644664")
print("Seat to Part plugin loaded")
Button.Click:connect(function()
local exist = game.CoreGui:findFirstChild'Info'
if(exist==nil)then
local gui = Instance.new("ScreenGui",game.CoreGui)
gui.Name = "Info"
local txt = Instance.new("TextLabel",gui)
txt.Name = "HelpText"
txt.Size = UDim2.new(1,0,0,25)
txt.TextStrokeTransparency = 0
txt.TextColor3 = Color3.new(1,1,1)
txt.Text = "Click on a vehicle seat to transform it into a part"
txt.BackgroundTransparency = 1
else
game.CoreGui.Info:Destroy()
end
local set = game:GetService("Selection")
set.SelectionChanged:connect(function()
local exist = game.CoreGui:findFirstChild'Info'
if(exist~=nil)then
print("exists")
if set.ClassName == "Seat" or set.ClassName == "VehicleSeat" then
print("is seat")
local p = Instance.new("Part")
p.BrickColor = set.BrickColor
p.Material = set.Material
p.Reflectance = set.Reflectance
p.Transparency = set.Transparency
p.Name = set.Name
p.Parent = set.Parent
p.CustomPhysicalProperties = set.CustomPhysicalProperties
p.Anchored = set.Anchored
p.Archivable = set.Archivable
p.CanCollide = set.CanCollide
p.Locked = set.Locked
p.Shape = set.Shape
p.Size = set.Size
p.BackParamA = set.BackParamA
p.BackParamB = set.BackParamB
p.BackSurfaceInput = set.BackSurfaceInput
p.BottomParamA = set.BottomParamA
p.BottomParamB = set.BottomParamB
p.BottomSurfaceInput = set.BottomSurfaceInput
p.FrontParamA = set.FrontParamA
p.FrontParamB = set.FrontParamB
p.FrontSurfaceInput = set.FrontSurfaceInput
p.LeftParamA = set.LeftParamA
p.LeftParamB = set.LeftParamB
p.LeftSurfaceInput = set.LeftSurfaceInput
p.RightParamA = set.RightParamA
p.RightParamB = set.RightParamB
p.RightSurfaceInput = set.RightSurfaceInput
p.TopParamA = set.TopParamA
p.TopParamB = set.TopParamB
p.TopSurfaceInput = set.TopSurfaceInput
p.BackSurface = set.BackSurface
p.BottomSurface = set.BottomSurface
p.FrontSurface = set.FrontSurface
p.LeftSurface = set.LeftSurface
p.RightSurface = set.RightSurface
p.TopSurface = set.TopSurface
p.CFrame = CFrame.new(set.Position)
p.Rotation =  set.Rotation
p.RotVelocity = set.RotVelocity
p.Velocity = set.Velocity
print("config done")
set:Destroy()
print("origin demolished")
end
end
end)
end)

Basically, what I'm tryna do, is I'm tryna make it so ya click on the plugin button in the tray bar, then ya click on the seat that ya wanna transform into a part, then it'll transform it into a part. However, this doesn't work. When I select the part after clickin' on the button, it only prints "exists", not "is seat". How can I fix this?

2 comments

0

bump (does that work here?

0

No, old unanswered posts are automatically recycled to the top of the queue.

1 answer

Your problem is that set is a table. set[1] is the first part in the selection order. I updated your script to reflect this:

local PluginManagerObject = PluginManager()
local Plugin = PluginManagerObject:CreatePlugin()
local Toolbar = Plugin:CreateToolbar("Seat to Part Plugin")
local Button = Toolbar:CreateButton("Seat > Part","Transform a seat to a part in just a few clicks!","http://www.roblox.com/asset/?id=516644664")

print("Seat to Part plugin loaded")

Button.Click:connect(function()
	local exist = game.CoreGui:findFirstChild'Info'
	if(exist==nil)then
		local gui = Instance.new("ScreenGui",game.CoreGui)
		gui.Name = "Info"
		local txt = Instance.new("TextLabel",gui)
		txt.Name = "HelpText"
		txt.Size = UDim2.new(1,0,0,25)
		txt.TextStrokeTransparency = 0
		txt.TextColor3 = Color3.new(1,1,1)
		txt.Text = "Click on a vehicle seat to transform it into a part"
		txt.BackgroundTransparency = 1
	else
		game.CoreGui.Info:Destroy()
	end
	
	local set = game:GetService("Selection")
	set.SelectionChanged:connect(function()
		local exist = game.CoreGui:findFirstChild'Info'
		if(exist~=nil)then
			print("exists")
			local part = set[1];
			if part.ClassName == "Seat" or part.ClassName == "VehicleSeat" then
				print("is seat")
				local p = Instance.new("Part")
				p.BrickColor = part.BrickColor
				p.Material = part.Material
				p.Reflectance = part.Reflectance
				p.Transparency = part.Transparency
				p.Name = part.Name
				p.Parent = part.Parent
				p.CustomPhysicalProperties = part.CustomPhysicalProperties
				p.Anchored = part.Anchored
				p.Archivable = part.Archivable
				p.CanCollide = part.CanCollide
				p.Locked = part.Locked
				p.Shape = part.Shape
				p.Size = part.Size
				p.BackParamA = part.BackParamA
				p.BackParamB = part.BackParamB
				p.BackSurfaceInput = part.BackSurfaceInput
				p.BottomParamA = part.BottomParamA
				p.BottomParamB = part.BottomParamB
				p.BottomSurfaceInput = part.BottomSurfaceInput
				p.FrontParamA = part.FrontParamA
				p.FrontParamB = part.FrontParamB
				p.FrontSurfaceInput = part.FrontSurfaceInput
				p.LeftParamA = part.LeftParamA
				p.LeftParamB = part.LeftParamB
				p.LeftSurfaceInput = part.LeftSurfaceInput
				p.RightParamA = part.RightParamA
				p.RightParamB = part.RightParamB
				p.RightSurfaceInput = part.RightSurfaceInput
				p.TopParamA = part.TopParamA
				p.TopParamB = part.TopParamB
				p.TopSurfaceInput = part.TopSurfaceInput
				p.BackSurface = part.BackSurface
				p.BottomSurface = part.BottomSurface
				p.FrontSurface = part.FrontSurface
				p.LeftSurface = part.LeftSurface
				p.RightSurface = part.RightSurface
				p.TopSurface = part.TopSurface
				p.CFrame = CFrame.new(part.Position)
				p.Rotation =  part.Rotation
				p.RotVelocity = part.RotVelocity
				p.Velocity = part.Velocity
				print("config done")
				part:Destroy()
				print("origin demolished")
			end
		end
	end)
end)

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