hello everyone, I have one problem when I click on this button, I get an offer to buy a gamepass and when I don’t buy it, the autoclicker starts working for me help fix it
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepasId = 251630884
local function ownsgamepass(userId, gamepassId)
local s,res = pcall(MarketPlaceService.UserOwnsGamePassAsync, MarketPlaceService, userId,
gamepassId)
if not s then
res = false
end
return res
end
local cps = 100 -- clicks per second
local active = false
script.Parent.MouseButton1Click:Connect(function()
active = not active
script.Parent.Round.ImageColor3 = Color3.fromRGB(234,0,0)
script.Parent.Text = "Off"
end)
local player = game:GetService("Players").LocalPlayer
while true do
if player and active and player.Character then
script.Parent.Round.ImageColor3 = Color3.fromRGB(0,255,0)
script.Parent.Text = "On"
local tool = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool")
if tool then
tool:Activate()
end
end
wait(1/cps)
script.Parent.MouseButton1Click:Connect(function()
active = not active
end)
end
Your code is flawed in a bunch of ways.
I’ve fixed up the code and added some comments to try and explain it:
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassId = 251630884
local OwnsGamepass = false
local function ownsgamepass(userId, gamepassId)
local s,res = pcall(MarketPlaceService.UserOwnsGamePassAsync, MarketPlaceService, userId,
gamepassId)
if not s then
res = false
end
OwnsGamepass = res -- You never actually called ownsgamepass. I made it serve a purpose within this script.
return res
end
local cps = 60 -- Can be a maximum of 60
local active = false
script.Parent.MouseButton1Click:Connect(function()
active = not active
script.Parent.Round.ImageColor3 = Color3.fromRGB(234,0,0)
script.Parent.Text = "Off"
end)
local player = game:GetService("Players").LocalPlayer
ownsgamepass(player.UserId, gamepassId)
while true do
if active and player.Character and OwnsGamepass then -- The player will always exist in a local script.
script.Parent.Round.ImageColor3 = Color3.fromRGB(0,255,0)
script.Parent.Text = "On"
local tool = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Tool")
if tool then
tool:Activate()
end
end
-- The script.Parent.MouseButton1Click thing would cause the number of times it fire to increase dramatically over time, so I removed it
task.wait(1/cps) -- task.wait allows for 1/60 intervals rather than 1/30 intervals
end
Well I don’t know how you have your scripts setup. It worked fine when I tested it. Please provide additional context and information or I am unable to provide further help
Is the id of the gamepass correct at the top of the script?
Where were you trying to call the owngamepass function from?
Where are you prompting the player to purchase the gamepass from?
What happens when you use the code I provided?
in test mode, you get a user id like -1, -2, -3 etc. You don’t get your normal UserID. The code ‘doesn’t work’ because you don’t have the gamepass on the test account.