How to detect same names Easy fix i quess

So I am needing like if i have block named “Noob” and have 4 other “Noob” named blocks. How I can make every block fire the same script not only the original noob, but all the others too.


local clicker = game.Workspace.Noob.Seller -- I have 4 other blocks named by Noob so Ye

local mps = game:GetService("MarketplaceService")
local gamepass_id = 13538006


clicker.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players.LocalPlayer
		mps:PromptGamePassPurchase(player, gamepass_id)
	end


end)

mps.PromptGamePassPurchaseFinished:Connect(function(player, id, purchased)
	if id == gamepass_id and purchased then
		game.ReplicatedStorage.Give6:FireServer()
	end
end)

Thanks - Do0gdemon

Add the Touch script in each of the block/Noob

This is in local script it would not work.

Actually its not recomend to use touch script in local script as it would make errors

Wiat i try to put it into there!

Okay it doesn’t work in normal script inside there because Its marketplace thngy.

there is a mistake in your script u cannot use local player in script
try this:

clicker.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:FindFirstChild(hit.Parent.Name)
		mps:PromptGamePassPurchase(player, gamepass_id)
	end


end)

mps.PromptGamePassPurchaseFinished:Connect(function(player, id, purchased)
	if id == gamepass_id and purchased then
		game.ReplicatedStorage.Give6:FireServer()
	end
end)
1 Like

Where i put this in local script or normal?

normal script -------------------

You want to use a loop through a table.

  17:15:00.906  Workspace.Noob.Seller.Script:10: attempt to index nil with 'PromptGamePassPurchaseFinished'  -  Server - Script

Not working sry

did u set a variable for mps as Local mps = game:GetServce("MarketplaceService")

No i tried ur script sir. I am maybe trying to find solution for local script. I have hear like findfirstchildofClass would it work?

no, the findfirstchild is actually finding the player name whereas findFirstChildOfClass will only find stuff with a ClassName like script, Humanoid etc

1 Like

lol i forget i putted the two extra lines code and BOOM works thanks bro!

1 Like

?

LocalScripts can use the Touched signal, it doesn’t produce errors. So long as you’re conscious of where you’re placing your LocalScript (that being, in a container that can run client-side code), Touched is perfectly fine to use on the client.