Need help with a bit of code in Pet Shop

  1. What do you want to achieve?

for my shops text button to write (pet…name) in output when clicked.

  1. What is the issue?

Keep getting this same (infinite yield) in output, Maybe my Module in ServerScript is not being activated no Idea, Followed You-tuber Alvin Egg opening

  1. What solutions have you tried so far?

I tried adding a timeout to the end of my script which solves the infinite yield but I could never get the button to work… any help would be nice

searched on dev forums, YouTube comments, also on google(+3 pages) Determined to figure out where the issue is.

These are the scripts in my current build

ServerServiceScript Pet Module

local petModule = {}

petModule.pets = {
	
	["Legendary"] = {
		game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("IceBunny");
	};
	
	["Epic"] = {
		game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Reindeer");
	};
	
	["Rare"] = {
		game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Bee");
	};
	
	["Common"] = {
		game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Reindeer");
		game.ReplicatedStorage:WaitForChild("Pets"):WaitForChild("Bear");
  		
	};
	
}



petModule.rarities = {
	
	["Legendary"] = 5;
	
	["Epic"] = 15;
	
	["Rare"] = 30;
	
	["Common"] = 50;
	
	
}

petModule.chooseRandomPet = function()
	
	local randomNumber = math.random(1,100)
	
	local counter = 0
	
	for rarity, weight in pairs(petModule.rarities) do
		counter = counter + weight
		if randomNumber <= counter then
			
			local rarityTable = petModule.pets[rarity]
			local chosenPet = rarityTable[math.random(1,#rarityTable)]
			
			return chosenPet
			
		end
		
	end
end


return petModule

My local script located in my Textbutton

you should do those checks on the server also [THE MINUS] and server modules cant be accessed by clients so put it in replicated storage so it can be shared modules

1 Like

I see that you are using MouseClick on a GUI object, when you need to use MouseButton1Click. Also, you should be subtracting values on the server, not on a local script.

1 Like

thanks for the mouse button click! also if I remove the values from the button wouldn’t I need to attach the button in another script to know what’s being clicked? also wouldn’t I be able to get this method working as is or is it exploitable that’s why I should change it

it is exploitable you should do already what i said its a fix though

You would just need to do script.Parent.TextButton.MouseButton1Click:Connect(function() instead. Well, it can be exploitable, but the values won’t actually subtract if you are doing it from the client. All you would need to do is that when the button is clicked, it fires an event. Then you can do checks to see if the player has enough money on the server, and everything else. There’s really no need to change the location of your module script by doing it through a remote event.

1 Like

The client cannot access the contents of server storage.
Put the module inside ReplicatedStorage instead

1 Like

Anything labeled as server in general cannot be accessed through the client. For the sake of simplicity as I can see you’re just starting out try ReplicatedStorage instead. If it were up to me I’d get the contents from the Server with a Remote Function at the client’s load and return the contents of the module you desire. So you can try that if you want to keep that data on the server side.

1 Like