How to detect what part player has touched (get the name of the part etc)

I need this for a orb collecting system

Could you provide any more information? Do you want to get the name of the player that touched the part? Is the collection system the only thing you need it for? What do you want to happen when a player touches the orb?

I want the orb to disapear but i cant get the name of the orb

Does the player have any values, e.g. money, that you want to change when they touch it?

1 Like

You could group all the orbs into a folder in the Workspace and manage it from the ServerScriptService, an example might be:

local folder = game.Workspace.Folder --change to your folder

for _, orb in pairs(folder:GetChildren()) do
    orb.Touched:Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not player then return end
        player.leaderstats.Money.Value += 25 --an example of a value to update
        orb.Transparency = 1
        orb.CanTouch = false
        wait(5)
        orb.Transparency = 0
        orb.CanTouch = true
    end)
end

This code would give the player 25 money when they walk over it.

1 Like

I tried using a remote but this is a better idea thanks.

2 Likes

Glad I could help. Just remember that you might want to add a buffer so the player is not constantly getting money. An example to add to the above code:

local folder = game.Workspace.Folder --change to your folder
local touchBuffer = false

for _, orb in pairs(folder:GetChildren()) do
    if touchBuffer then return end --if it is on cooldown
    orb.Touched:Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not player then return end
        touchBuffer = true
        player.leaderstats.Money.Value += 25 --an example of a value to update
        orb.Transparency = 1
        orb.CanTouch = false
        touchBuffer = false
        wait(5)
        orb.Transparency = 0
        orb.CanTouch = true
    end)
end
1 Like

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