Help to fix a promblem

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
3 Likes

please help me fix this necessary thing

1 Like

guys, please help me fix this already, perhaps aaaaaaa

1 Like

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


1 Like

excuse me I tried your script but when I click on it it doesn’t work

1 Like

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

1 Like

what would you like me to throw you immensely?

1 Like

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?

1 Like

here I am playing on my account, it works, but when I switch to test mode, it does not click

1 Like

What do you mean?
By test mode, do you mean the one where you can have multiple test users at once in studio?

1 Like

Could you give me a screen-recording (if you dont have obs you can just use roblox’s recorder) so I can see better of what you’re talking about?

1 Like

which button should I press to record?

1 Like

Where are you getting “API” from in this?


here I am playing on my account, it works, but when I switch to test mode, it does not click

By test mode, do you mean the one where you can have multiple test users at once in studio?

2 Likes

yes, that’s how I play from the main account, I can click and when I switch to test mode, I can’t do it, only off is not pressed and that’s it

1 Like

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.

1 Like

You can go to View and then press “Video Record”.

Or you can go to Pause Menu > Record > Press “Record Video”

Or if you have OBS you can just press “Start Recording”.

Then grab your file (the footage) and drop it into DevForum as a reply/comment by pressing the little Upload button.

1 Like

Right when I was about to see the footage… Why did you delete it?

1 Like

Sorry mistake, how can I send a video from Roblox without errors?

1 Like

there is another video, not what I shot, sorry

2 Likes

robloxapp-20230908-1636535.wmv (99.1 KB)

2 Likes