#LocalScript Help

13 messages · Page 1 of 1 (latest)

sharp gull
#

Basically I have a localscript that check a players balance and unlock a pathway if they meet the criteria. In that local script, how can I get the name of the workplace object they came into contact with and print that value to console? For example, if they walked into a wall model or part named "Wall23" I would want it to print Wall23 in console when they collide with it. Any help would be greatly appreciated! Thanks!

limpid cipher
sharp gull
# limpid cipher
local diamonds = player:WaitForChild("leaderstats"):WaitForChild("Diamonds")

local reqDia = 10
local part = game.Workspace.barrier2.barrier2a

diamonds.Changed:Connect(function()
    if diamonds.Value >= 10 then
        part.CanCollide = false
        wait(5)
        part.CanCollide = true
    else
        part.CanCollide = true
    end
end)```
#

There is the code, Although I am manually declaring a model named barrier2 in this code. I want to be able to programmatically get the name of the item they are colliding with

sharp gull
#

Ok. I tried this:

local diamonds = player:WaitForChild("leaderstats"):WaitForChild("Diamonds")

local Workspace = workspace
local Model = Workspace.barrier2

local function OnTouched(TouchedPart)
    local TouchedModel = TouchedPart:FindFirstAncestorOfClass("Model")
    if not TouchedModel then return end
    print(TouchedModel.Name)
end

for _, Child in ipairs(Model:GetChildren()) do
    if not (Child:IsA("BasePart")) then continue end
    Child.Touched:Connect(OnTouched)
end```
#

But it is returning my player name

#

in console

limpid cipher
#
for _,v in pairs(Model:GetDescendants()) do
  if v:IsA("BasePart") then
    v.Touched:Connect(function(hit)
      if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        if diamonds.Value >= 10 then
          v.CanCollide = false
          task.wait(5)
          v.CanCollide = true
        else
          v.CanCollide = true
        end
      end
    end)
  end
end
limpid cipher
sharp gull
#

Got it! I just added print(v.name) and it return what I was expecting to console

#

Thank you