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)
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.
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.
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.
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?
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!
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
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