Print part position based on part in workspace identified by script Attribute

I am creating a game and having issues with a shovel I am creating.

I want the Shovel to only run the dig function if it detects the player inside a part/region
The part name is an attribute inside the shovel tool, The part is in workspace.

Here is the full script:

local MouseData = Instance.new(“RemoteFunction”,script.Parent)
local KeyEvent = Instance.new(“RemoteEvent”,script.Parent)
local Tool = script.Parent
local Gui = script.SoilGUI
local Handle = Tool.Handle
local attribute = script.Parent.Configuration
local Attrib = script.Parent.Configuration
local digpart = game.Workspace:FindFirstChild(Attrib:GetAttribute(“Dig_Region_Block_Name”))
local Hitting = false

script.Parent.Activated:Connect(function()
if not Tool.Enabled then return end
Swing()
local Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
if Player.Character.Humanoid.Health <= 0 then return end
if Player then
local Target,HitPos = MouseData:InvokeClient(Player)
if Target and (HitPos - Handle.Position).Magnitude <= Attrib:GetAttribute(“ReachDistance”) then
if Target == workspace.Terrain then
if digpart:GetPartsInPart(Player.humanoid) then
Tool.Enabled = false
CreateDust(HitPos)
workspace.Terrain:FillBall(HitPos,Attrib:GetAttribute(“DigSize”) ,Enum.Material.Air)
Handle.Dig:Play()
if Attrib:GetAttribute(“ConsumeSoil”) then
Attrib:SetAttribute(“Soil”, Attrib:GetAttribute(“Soil”) + 1)
end
if Attrib:GetAttribute(“GuiEnabled”) then
KeyEvent:FireClient(Player,Gui,Attrib:GetAttribute(“Soil”))
end
wait(Attrib:GetAttribute(“Cooldown”))
Tool.Enabled = true
end
end
end
end
end)

1 Like

The issue might be that you have forgot to put a wait() in the while true do loop

position is lowercase in your script, change it to Position

1 Like

I did both of these changes and now gives this error:

09:55:02.001 local digpart = game.Workspace:FindFirstChild(script.Parent.Configuration:GetAttribute(“Dig_Region_Block_Name”))

while true do
wait(0.5)
print(digpart.Position)
end:

1: attempt to index nil with ‘Parent’ - Edit

scripts should have parents tho? idk whats the issue

try, local digpart = script.Parent.Configuration:GetAttribute(“Dig_Region_Block_Name”)

Ok so here’s what I deduce. The configuration is in startergui, its parent is a local script which is also the parent of the script you’re showing here. Server Scripts cannot work in StarterGui.
Move this script to somewhere else where a server script can work (SSS, Workspace) and write this instead

local digpart = game.Workspace:FindFirstChild(game.StarterGui.Tool.LocalScript.Configuration:GetAttribute("Dig_Region_Block_Name")) -- Change this to your tool and the local script in it

while task.wait(0.5) do
	print(digpart.Position)
end

could you explain more in depth what youre trying to achieve? im sorry i dont really quite understand the original post

I updated the main post to reflect more accurately what I am trying to do.

is the check involving the region or the “dig area part” nested in a function or is it somewhere else. neverming i found it :sob::sob::sob::sob:

okay so what might be happening is that the checks before the dig area check might not be passing so the dig area check does not run

THE OTHER problem might be that since this runs on a local script it doesnt wait before the dig area is loaded (but this is unlikely because it would probably error if its trying to check the position of nil but it doesnt hurt to just make it WaitForChild either)

getpartsinpart must be called by the workspace


so you can create an array with it

...
local arr = workspace:GetPartsInPart(digpart)

-- do your checks with that arr