The error message indicates that the script is trying to access the sterownik member of the script.Parent.Parent object, which does not exist. It seems like the script's hierarchy needs to be fixed to correctly reference the sterownik object and its child Dest, which contains the Code value.
Without knowing the exact structure of your hierarchy in Roblox, I can't provide a specific solution, but I'll give you a general approach to debug this issue.
-
Make sure the script's parent's parent (script.Parent.Parent) actually contains a child named sterownik. You might be missing a reference in the hierarchy. If sterownik is not at the expected location, you'll need to find where it is and reference it correctly.
-
Ensure that sterownik has a child named Dest, which in turn should have a child named Code holding a Value.
Assuming sterownik is a direct child of the Workspace based on the error message, and not the Body Model (which seems to be the parent of the script), you'll need to reference it using the exact path to it. Here's how you might modify the script:
script.Parent.Touched:Connect(function(Part)
-- Check if sterownik is indeed a direct descendant of Workspace.
local sterownik = workspace:FindFirstChild("sterownik")
if not sterownik then
warn("sterownik was not found in Workspace")
return
end
-- Check if sterownik has a valid Dest member with a Code value.
local Dest = sterownik:FindFirstChild("Dest")
if not Dest then
warn("Dest was not found in sterownik")
return
end
local codeValue = Dest:FindFirstChild("Code")
if not codeValue then
warn("Code was not found in Dest")
return
end
-- Play the sound based on the part touched and code value.
if Part.Name == "Lesno" and codeValue.Value ~= "4000" then
local LesnoSpeaker = script.Parent.Parent:FindFirstChild("Speaker")
if LesnoSpeaker then
local sound = LesnoSpeaker:FindFirstChild("Lesno")
if sound then
sound:Play()
else
warn("Lesno sound was not found in Speaker")
end
else
warn("Speaker was not found in script.Parent.Parent")
end
elseif Part.Name == "Zalesie" and codeValue.Value ~= "4000" then
-- Your original script doesn't have an action for this condition.
-- Add the desired behavior here.
end
end)
Note that this code now includes some checks. If they fail (because a certain object doesn't exist), it will output a warning to the console, and the warn statements describe which object is missing. Adjust the references based on your actual game hierarchy.