is there any way for me to find out which part was played? Whether it was Coin2 or Coin3? script:
local player = game.Players.LocalPlayer function touch (hit) print("touch") print("Part "..Coin3 or Coin2 "touched") end workspace.Coin3.Touched:Connect(touch) workspace.Coin2.Touched:Connect(touch)
local player = script.Parent local humanoid = player:WaitForChild("Humanoid") humanoid.Touched:Connect(function(hit) if hit.Name == "Coin2" then print("Coin2 was touched.") elseif hit.Name == "Coin3" then print("Coin3 was touched".) end end)
This will print what coin was touched. Make sure you put this as a local script into StarterCharacterScripts!
I think it would be easier just to use tables to solve this problem.
local player = game.Players.LocalPlayer local coins = {workspace:WaitForChild("Coin3"), workspace:WaitForChild("Coin2")} for _,coin in pairs(coins) do coin.Touched:Connect(function(hit) print(coin.Name) end) end
What's happening is I am taking the contents of the table and adding a touched event for each element of the table.
Hi Iytew! There is a much simpler way of doing this.
function onTouched(hit) print(hit.Name.. " was touched!") end script.Parent.Touched:Connect(onTouched)
We can get the name of the part that touched that specific part.
Hope I helped! LennyPlayzYT