How to script a button that inserts a cylinder?

Alright, I need a button that can insert a cylinder, only 2 cylinders without the gamepass. However if you have the gamepass, you can have up to 5 cylinders at once. (Might seem weird with cylinders, just go with me here.

local ItemOneImage = script.Parent

ItemOneImage.MouseButton1Click:Connect(function()
	local Part = Instance.new("Part")
	Part.Size = Vector3.new(30,17,24)
	Part.Position = Vector3.new(0,0,0)
	Part.Parent = workspace
end)

For anyone needing it, the gamepass link is here: More Rockets Ability - Roblox

Thanks!

local ItemOneImage = script.Parent
local marketplaceService = game:GetService("MarketplaceService")

ItemOneImage.MouseButton1Click:Connect(function(hit)
	if marketplaceService:UserOwnsGamePassAsync(hit.Parent.Name, 18261191) then
for i = 1, 5 do
local Part = Instance.new("Part")
	Part.Size = Vector3.new(30,17,24)
	Part.Position = Vector3.new(0,0,0)
	Part.Parent = workspace
wait(0.1)
else
for i = 1, 3 do
local Part = Instance.new("Part")
	Part.Size = Vector3.new(30,17,24)
	Part.Position = Vector3.new(0,0,0)
	Part.Parent = workspace
wait(0.1)

end
end)

I am not sure if that’s what you are trying to achieve, but the code above spawns 3 rockets at once if the player doesn’t own the gamepass and spawns 5 rockets at once if they own the gamepass. Feel free to change the code inside the if statement if you aren’t completely satisfied.

Wait, is this code inside a GUI script?

It is a script inside of a ImageButton.

If you want to make a button that inserts a cylinder try this…

part.Shape = Enum.PartType.Cylinder

I get it, its adding the gamepass though

Change it to a local script, and fire a remote event to the server to check if the player owns the gamepass and then insert the cylinder from the server. I will provide a script once available.

Alright! Take your time! :smiley:

Local Script: (under the image button)

local button = script.Parent
local event = pathToYourEvent

button.MouseButton1Click:Connect(function()
event:FireServer()
end)

Server Script: (preferrably in ServerScriptService)

local event = pathToYourEvent
local ms = game:GetService("MarketplaceService")
local gamepassId = 18261191

event.OnServerEvent:Connect(function(player)
if ms:UserOwnsGamePassAsync(player.UserId, gamepassId) then
print("User owns gamepass!")
-- Put the code you need here that spawns in 5 rockets
else
print("User doesn't own the gamepass.")
-- Put the code you need here that spawns 3 rockets.
end)

Make sure to change the event variable accordingly to a remote event path, located under ReplicatedStorage.

Interesting. My code would be this:

local ms = game:GetService("MarketplaceService")
local gamepassId = 18261191

event.OnServerEvent:Connect(function(player)
	if ms:UserOwnsGamePassAsync(player.UserId, gamepassId) then
		print("User owns gamepass!")
		-- Put the code you need here that spawns in 5 rockets
		for i = 1, 5 do
			local Part = Instance.new("Part")
			Part.Size = Vector3.new(30,17,24)
			Part.Position = Vector3.new(0,0,0)
			Part.Parent = workspace
		print("User doesn't own the gamepass.")
		-- Put the code you need here that spawns 3 rockets.
		for i = 1, 3 do
			local Part = Instance.new("Part")
			Part.Size = Vector3.new(30,17,24)
			Part.Position = Vector3.new(0,0,0)
			Part.Parent = workspace
			wait(0.1)

		end
	end)```

I seem to be getting a error. In ReplicatedStorage I added a RemoteEvent called "RemoteEventPath" any idea why I got errors?

All parts I believe have a shape property. When you insert the part, change that to cylinder. I am not sure if you also need help with this, but here.

You erased the else statement from above. It would be like:

Create a remote event in ReplicatedStorage called RocketAdder

Local script:

local button = script.Parent
local event = game.ReplicatedStorage.RocketAdder

button.MouseButton1Click:Connect(function()
event:FireServer()
end)

Server script:

local event = game.ReplicatedStorage.RocketAdder
local ms = game:GetService("MarketplaceService")
local gamepassId = 18261191

event.OnServerEvent:Connect(function(player)
if ms:UserOwnsGamePassAsync(player.UserId, gamepassId) then
print("User owns gamepass!")
for i = 1, 5 do
			local Part = Instance.new("Part")
			Part.Size = Vector3.new(30,17,24)
			Part.Position = Vector3.new(0,0,0)
			Part.Parent = workspace
wait(0.1)
end
else
print("User doesn't own the gamepass.")
	for i = 1, 3 do
			local Part = Instance.new("Part")
			Part.Size = Vector3.new(30,17,24)
			Part.Position = Vector3.new(0,0,0)
			Part.Parent = workspace
			wait(0.1)

		end
end
end)

Hopefully this addresses all your enquiries and concerns! :grinning:

Last thing here.- you corrected it haha!

Hold on, ridiculous thing here. But it seems the end dosent like the ) or without it. Any ideas?

Yep, I forgot to add an end. It should be fxed now.

Sorry. I am dragging this on, however it spawns the amount you can spawn at once. I want it so you spawn 1 at once and it spawns INFRONT of you. Also its not cylinders, its normal blocks

I am not a scripter, but c’mon, is that really a real scripting term?

Anyone got any ideas on this? read the code above somewhere…

Asuming the gamepass already works:

local event = game.ReplicatedStorage.RocketAdder
local ms = game:GetService("MarketplaceService")
local gamepassId = 18261191
event.OnServerEvent:Connect(function(player)
local Character = player.Character
if ms:UserOwnsGamePassAsync(player.UserId, gamepassId) then
print("User owns gamepass!")
for i = 0, 1,1 do
			local Part = Instance.new("Part")
                       Part.Shape = Enum.PartType.Cylinder
			Part.Size = Vector3.new(30,17,24)
			Part.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)
			Part.Parent = workspace
wait(0.1)
end
else
warn("User doesn't own the gamepass.")
end

If you have any additional problems then please do tell. Don’t be hesitant to ask for more.