Hey i’m DevFoll and i used a for i, v in pairs() loop for touched event but i need to find out which part got touched NOT BODY PART JUST THE part the player touched
for i, v in pairs(game.Workspace.Checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local ColorChangingScript = game.ReplicatedStorage.ColorChangingScript:Clone()
ColorChangingScript.Parent = Player.PlayerGui
ColorChangingScript.Disabled = false
game.ReplicatedStorage.PartThatGotTouched.Value = --idk?
game.ReplicatedStorage.ChangeColor:FireClient(Player)
end
end)
end
and when i thought i found out i struggled with somthing else idk how to refrence it when definding where the part is lemme show you
Is your PartThatGotTouched an object value or a string value? Also does all of the Checkpoints children have a different name?
If the PartThatGotTouched is a StringValue and all of the Checkpoints children have different names then try this
Try this
for i, v in pairs(game.Workspace.Checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local ColorChangingScript = game.ReplicatedStorage.ColorChangingScript:Clone()
ColorChangingScript.Parent = Player.PlayerGui
ColorChangingScript.Disabled = false
game.ReplicatedStorage.PartThatGotTouched.Value = v.Name
game.ReplicatedStorage.ChangeColor:FireClient(Player)
end
end)
end