Hello, i wanna make it print “hello” when player touches one of the certain parts. But i cant do that. Is there a way to do it?
(There is 5-4 parts named “Yehu”)
Here is code:
script.Parent.Yehu.Touched:Connect(function()
print(“hmm idk”)
end)
Hello, i wanna make it print “hello” when player touches one of the certain parts. But i cant do that. Is there a way to do it?
(There is 5-4 parts named “Yehu”)
Here is code:
script.Parent.Yehu.Touched:Connect(function()
print(“hmm idk”)
end)
Make a folder and put all the parts in there
Example:
local Parts = workspace.FOLDERNAME:GetChildren()
Parts.Touched:Connect(function(hit)
print("Hello")
end
Something like that
I think this should work:
local wsdes = workspace:GetDescendants()
for i,v in pairs(wsdes) do
if v.Name = "Yehu" then
local yehu_part = v
yehu_part.Touched:Connect(function()
print("Hello")
end)
end
end
Add a check to see if it was a player that touched the part, and use one of the answers above to easily add the .Touched event to each part (I’d reccomend putting them all the Yehu parts into a single folder/model to avoid needlessly iterating over the entire workspace)
Object.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then -- check if it was a player that touched the part
print("Hello")
end
end)
Uh it gives this error (aye is model’s name)
Have you considered using collection services to avoid repeating script instances?