I'm confused on why this script won't work

game.Players.PlayerAdded:Connect(function(player)
local bruh = script.Parent
local Bank = game.Workspace.Bank_Model

local function explode()
	for _, item in pairs(Bank:GetChildren()) do
		if item:IsA('part') or item:IsA('UnionOperation') then
			item.Anchored = false
			local explosion = Instance.new('Explosion')
			explosion.Position = item.Position
			explosion.parent = game.Workspace
		end
	end
end
script.Parent.Interaction.Triggered:Connect(explode)
1 Like

This wouldn’t work, part isnt a Class according to Luau, Do you mean Part?

Instead of checking if Its a Part, you can Instead Check if its a BasePart so it would include any Part.
Also, you can simplify the Usage of game.Workspace with just workspace which is a Independent Variable.

	for _, item in pairs(Bank:GetChildren()) do
		if item:IsA("BasePart") or item:IsA('UnionOperation') then
			item.Anchored = false
			local explosion = Instance.new('Explosion')
			explosion.Position = item.Position
			explosion.parent = workspace
		end
	end

2 Likes

Please elaborate, we can’t understand the problem only with the Script

Right off the bat, you still need to close the :Connect(function()) you defined at the top of your script with an end) at the second to last line, but elaboration would be helpful as mentioned above.

Um no?

Thats not what he is doing, He is not doing this:

Event:Connect(function() -- creates Connection with new function

end)

He is doing this:

local function ex()

end

Event:Connect(ex) -- applies function to :Connect

Which is valid.

so i have a proximity prompt in a NPC that when you press e it makes a model i named Bank_Model in the workspace explode

He still requires an end) at the end of the function in order to close off the first line of the script, that being game.Players.PlayerAdded:Connect(function(player). While I understand he wants to connect a secondary Event within the primary function, he can simply move the end) I recommended after the last line of the script.

Okay, but what’s the problem, is there any error? Have you Reid adding print statements?

Ah I see what you mean

Keep in mind, that this may not be the entire function that he has, He doesnt have to include that bit, just the bit that isnt working unless the other bit is also important.

there is no error prints and thats whats mostly confusing me

I mean have you tried adding print statements and see if they print?

i copied the entire code in the script so maybe grizz is right?

For sure, but I say we focus our minds on the task at hand, that being the proximity NPC failing!

The code below should provide you a better start @amazingplaze123! Let me know if you need any further help or it errors. :wink:

Revised Function
game.Players.PlayerAdded:Connect(function(player)
	local bruh = script.Parent
	local Bank = game.Workspace.Bank_Model

	local function explode()
		for _, item in pairs(Bank:GetDescendants()) do
			if item:IsA("BasePart") or item:IsA("UnionOperation") or item:IsA("MeshPart") then
				item.Anchored = false
				local explosion = Instance.new('Explosion')
				explosion.Position = item.Position
				explosion.Parent = game.Workspace
                game.Debris:AddItem(explosion, 5) -- Destroys the item after 5 seconds.
			end
		end
	end
    
	script.Parent.Interaction.Triggered:Connect(explode)
end)

let me try that bldjjlddjasflajlajda

1 Like

workspace variable is deprecated I believe.

It’s a good habit to use game.Workspace because of that is a more detailed standardized path finding habit.

workspace isnt Deprecated.

There is another Variant known was Workspace (with a uppercase W) that is deprecated, but the lowercase version isnt, also, Roblox even shows the 3 Methods for them which is:

workspace
game.Workspace
game:GetService("Workspace")

All 3 work.

1 Like

yes thank you very much this helped

yep, I was pointing this one out: Workspace

Don’t use that one. I do however, apologize. You said: workspace

2 Likes

Its fine, Its can be a Common error to confuse Workspace and workspace, as they look similar, like how you can confuse Game and game, and many other Variants.

game -- OK
Game -- Deprecated

workspace -- OK
Workspace -- Deprecated

spawn() -- Somewhat Deprecated
Spawn() -- Deprecated

delay() -- Somewhat Deprecated
Delay() -- Deprecated

never knew there was such thing as capitalizing Spawn and Delay! wow! =)

1 Like