--// VARIABLES //--
local Players = game:GetService('Players');
local UserInputService = game:GetService('UserInputService');
local Player = Players.LocalPlayer;
local Character = Player.Character or Player.CharacterAdded:wait();
local PlayerGui = Player:WaitForChild('PlayerGui');
local Game_UI = PlayerGui:WaitForChild('Game_UI');
local Tip_Text = Game_UI.Tip_Text;
local Active = false;
local Object = nil;
--// FUNCTIONS //--
UserInputService.InputBegan:Connect(function(Input)
if (Active and Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Enum.KeyCode.E) then
Object.Config.Detect_Event:FireServer();
end;
end);
while wait(.05) do
Object = nil;
Active = false;
Tip_Text.Visible = false;
for _, Window in pairs(game.Workspace:GetChildren()) do
if Window:FindFirstChild("Center") then
local Magnitude = (Character.HumanoidRootPart.Position - Window.PrimaryPart.Position).magnitude;
if (Magnitude <= Window.Config.Range.Value) then
Tip_Text.Text = "Press E to open window";
Tip_Text.Visible = true;
Active = true;
Object = Window;
end;
end;
end;
end;
And here is error from output:
[13:44:21.455 - Players.honza2555.PlayerScripts.Client_Script:25: attempt to index field 'PrimaryPart' (a nil value)](rbxopenscript://www.dummy.com/dummy?scriptGuid=%7B8705C2B1%2DBFA4%2D42E1%2D9C90%2DBCCEE249D168%7D&gst=2#25)
13:44:21.456 - Stack Begin
[13:44:21.456 - Script 'Players.honza2555.PlayerScripts.Client_Script', Line 25](rbxopenscript://www.dummy.com/dummy?scriptGuid=%7B8705C2B1%2DBFA4%2D42E1%2D9C90%2DBCCEE249D168%7D&gst=2#25)
13:44:21.456 - Stack End
Also by the looks of it your trying to verify if it has a primaryparty by a child called center? I would just check if the window is a model and if primarypart is equal to nil
I would just print out which model doesn’t have a primarypart and fix it.
This is erroring because the Window, or the object that is currently getting looped doesn’t have a primary part, or maybe isn’t even a model.
You have to add an if statment to check if its a model, and if it has a primary part I assume.
for _, Window in pairs(game.Workspace:GetChildren()) do
if Window:IsA("Model") then
if Window.PrimaryPart then
if Window:FindFirstChild("Center") then
local Magnitude = (Character.HumanoidRootPart.Position -
Window.PrimaryPart.Position).magnitude;
if (Magnitude <= Window.Config.Range.Value) then
Tip_Text.Text = "Press E to open window";
Tip_Text.Visible = true;
Active = true;
Object = Window;
end
end
end;
end;
end;
end;
Sorry the ends are really wrong devforum should fix indenting
Yes, from your loop your indexing everything in workspace I would check which part/model it’s erroring on and try to better your checks. for example with checking if it’s a model and had a primarypart
It might still be possible that there is some lonely model that has no PrimaryPart set even though it has a Center child. That would explain why the current fix works and the former did not