Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to detect part touched?

I am using this script to add a touch event to a group of items. I want to add points when the item is touched and then remove it.

Every example shows that you use script.parent but I am not using a child script. So can I use this touch event to remove the item or do I have to use a child script?

1 answer

I dont fully understand wym in this but I believe to detect a part touched by player you would yeh use script.Parent add a script in the part doing this

script.Parent.Touched:Connect(function(plr) -- When the part is touched by character
local player = game.Players:GetPlayerFromCharacter(plr) -- gets player by the player touching
player.leaderstats.Points.Value += 1 -- Adds 1 point to player 
script.Parent:Destroy()-- Destroys the part
end) -- ends the script

I tested this so it works also if your points aint player.leaderstats.Points.Value change it to your currency Accept if it works and you needed this

1 comment

0

Yeah but I don't have a script in the part. I have a script in serverscriptservice that assigns the touched event. If I use script.parent it gives me serverscriptservice and not the part. I want I way to use this script to find the part with out putting a script in every collectable part.

This discussion is preserved as it was. New answers, comments, and votes are closed.