How apply script effect on multiple proximity prompts?

I want this script, which works fine on one door (left one in vid), to work on all the others.
Ive looked around on other posts to see if they had a similar problem but i couldnt find one and i dont see a reason for the script to not work as the doors names are exactly the same along with the children.

local unlockableP = game.Workspace.UnlockableParts

local boltParts = unlockableP.BoltCutterParts

local plr= game.Players.LocalPlayer.PlayerGui:WaitForChild("LockedAreaNotif")

local backG = plr.MainBackground.Background
local message = plr.MainBackground.Background.Message

local soundNotif = game.SoundService.LockedNotif
local lockCut = game.SoundService.LockCut


local part = boltParts.Door
local prompt = part.ProximityPrompt

backG.Position = UDim2.new(1, 0,0.817, 0)

prompt.Triggered:Connect(function(player)
	if player.Character:FindFirstChild("Bolt cutters") then
		lockCut:Play()
		part:Destroy()

	else
		soundNotif:Play()
		backG.Visible = true

		message.Text = part.Message.Value

		backG:TweenPosition(UDim2.new(0.689, 0,0.817, 0))

		task.wait(3)

		backG:TweenPosition(UDim2.new(1, 0,0.817, 0))

		task.wait(1)

		backG.Visible = false

	end

end)

Im pretty sure i have to change something here:

local part = boltParts.Door
local prompt = part.ProximityPrompt

so that the script can recognize more that just one door.

Yea you’ll have to change that. You can do this to apply the script to every door (since every door has the same name):

local plr= game.Players.LocalPlayer.PlayerGui:WaitForChild("LockedAreaNotif")

local backG = plr.MainBackground.Background
local message = plr.MainBackground.Background.Message

local soundNotif = game.SoundService.LockedNotif
local lockCut = game.SoundService.LockCut

backG.Position = UDim2.new(1, 0,0.817, 0)
for i, part in pairs(boltParts:GetChildren() do -- get all boltPart's children
if part.Name ~= "Door" then continue end -- skip if not a door
local prompt = part.ProximityPrompt

prompt.Triggered:Connect(function(player)
	if player.Character:FindFirstChild("Bolt cutters") then
		lockCut:Play()
		part:Destroy()

	else
		soundNotif:Play()
		backG.Visible = true

		message.Text = part.Message.Value

		backG:TweenPosition(UDim2.new(0.689, 0,0.817, 0))

		task.wait(3)

		backG:TweenPosition(UDim2.new(1, 0,0.817, 0))

		task.wait(1)

		backG.Visible = false

	end

end)
end
1 Like

Hi thanks for the help but on ‘do’ it tells me to close a bracket at line 21 but i dont see any problems around that column, do you know the solution to this? I am fairly new and this is the first time ive seen this error
image

You need a closing parenthesis for line 14 after GetChildren()

1 Like

You’re missing a “)”. You’re trying to type

for i, part in pairs(boltParts:GetChildren()) do
1 Like

damn idk how i didnt see that thanks :upside_down_face:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.