Can you help me to fix my script bug

Hi roblox devs today i got an Error in my script.that verify if user own the gamepass and connect to a function ,but its not woking i dont know why?i put it in serverscriptservice , can you help me to fix that script pls

local ms = game:GetService("MarketplaceService")
local passid = 718667987
local haspass = false

local rep = game:GetService("ReplicatedStorage")
local sword = rep:FindFirstChild("ClassicSword")






game.Players.PlayerAdded:Connect(function(player)
	

local success,error = pcall(function()
		haspass= ms:UserOwnsGamePassAsync(player.UserId,passid)
		if haspass then

			print(player.Name.."  own the pass") 
			
			game.Players.PlayerAdded:Connect(function(player)
				player.CharacterAdded:Connect(function(character)
					local hum = character:FindFirstChild("Humanoid")
					hum.WalkSpeed = 1000000 
					sword.Parent = player.Backpack
					
					
				end)               
			          
			end)  
			
		else
			print(error.."ow the passss  bro")
	end
		
		end)
	



end)

here is the script as you can explain its really a verify user own the gamepass.pls help me to fix the script Error.
and if help thanks! Enjoy!

Did the script work before today?

What is the error in your Output Window? It will let others know what to look for and on what line of the script the problem is.

i got nothing! idk why my roblox studio lag i think

but i have a good pc idk why its not working and yeah

its just do the print() why! and i got demotiver for my g :frowning_face:ame :

Your answers are a bit confusing. I understand that English may not be your first language, but please answer these questions in order, in only one post:

  1. Did your script work before today?
  2. You said "it just do the print() " but you need to say which of the prints it’s doing (“owns the pass” or “ow the passss”).
  3. Are there any errors printed in the Output window, and if yes then copy and paste the error here.
  4. You said Studio lags.
  • Is it only Studio that lags?
  • Does your game on the website?
  • Do you have any other scripts that would cause the lag?
  • Have you added any free models from the Toolbox that had scripts inside them?
  • Have you installed any plugins that may have harmful scripts that could be causing issues with your game?
  1. Is this a free model script that you are using?

Here’s a link to how to create Passes: Passes | Documentation - Roblox Creator Hub

its print(“skinogodest own the pass”) but not the Humanoid and i have not use free model i never use it soo i just used moon animator 2 and studio not lag i think don’t have any error and enjoy i can share you a video

but i have delet the script can u give an other script if you want!! :neutral_face: and enjoy!!!

You are calling game.Players.PlayerAdded in a game.Players.PlayerAdded, meaning this code will never run.

ok let me explain first lets remake but its just print(“skinogodest own the pass”) an let me explain and yeah

Exactly

Is the issue because you are waiting for another player to join the game and then setting up a event where you will get the next person that joins character and then setting their speed to what ever number that is.

already just print()

local ms = game:GetService("MarketplaceService")
local passid = 718667987
local haspass = false

local rep = game:GetService("ReplicatedStorage")
local sword = rep:FindFirstChild("ClassicSword")






game.Players.PlayerAdded:Connect(function(player)


	local success,error = pcall(function()
		haspass= ms:UserOwnsGamePassAsync(player.UserId,passid)
		if haspass then

			print(player.Name.."  own the pass") 

			
				player.CharacterAdded:Connect(function(character)
					local hum = character:FindFirstChild("Humanoid")
					hum.WalkSpeed = 10000
					sword.Parent = player.Backpack


				end)               

			

		else
			print(error.."ow the passss  bro")
		end

	end)




end)

Okay, since you clearly do not understand what I am telling you I will just give you code that will work.

local ms = game:GetService("MarketplaceService")
local passid = 718667987
local haspass = false

local rep = game:GetService("ReplicatedStorage")
local sword = rep:FindFirstChild("ClassicSword")






game.Players.PlayerAdded:Connect(function(player)
	local success,error = pcall(function()
		haspass= ms:UserOwnsGamePassAsync(player.UserId,passid)
		if haspass then
			print(player.Name.."  own the pass") 
			player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed = 10000
			sword.Parent = player.Backpack
		else
			print(error.."ow the passss  bro")
		end

	end)
end)
1 Like

thanks its working!! Enjoy bro but what is the difference between findfirstchild and findfirstchildofclass but i am a pro scrpter thanks !!!

FindFirstChild is pretty much Instance[“Item”]

FindFirstChildOfClass is finding the first child that has the class you put in as the arguement.

ok thanks!!! bc me i code more javascript so luau a bit new for me but i know good

but i want datastore can you help me to datastore(last question)

Simple and easy datastore for beginner scripters!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.