Proximity promt script not working (SCRIPT)

hello im trying to make a door but when the player opens the door they get shot.

i added a proximity promt and i put a local script inside it with script

-imporant note:
this is a script
-this is inside the proximity promt
-the gunshot is inside the door part
-nothing prints when i trigger it.

script:

local ui = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Die")

local menu = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Menu")

script.Parent.Triggered:Connect(function(plr)

print("hit")

script.Parent.Gunshot:Play()

ui.Visible = true

wait(0.5)

menu.Visible = true

print("everything good")

plr:WaitForChild("Character").Health = 0

print("HOPE")

end)


image

model: Part - Roblox

1 Like

I think that Local Scripts cannot run inside a Proximity Prompts.

1 Like

Are you running a local script in workspace, or are my eyes deceiving me?

1 Like

ok i changed it to a script but its not working

Are there any errors? chars(30)

yes but im not sure of the solution. to be honest i didnt see any before. heres the error: Workspace.Part.Door.Script:1: attempt to index nil with ‘WaitForChild’

image

script:

script.Parent.Triggered:Connect(function(plr)

     local ui = plr:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Die")
     local menu = plr:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Menu")

     print("hit")

     script.Parent.Gunshot:Play()

     ui.Visible = true

     wait(0.5)

     menu.Visible = true

     print("everything good")

     local character = plr.Character or plr.CharacterAdded:Wait()
     local humanoid = character:WaitForChild("Humanoid")

     humanoid.Health = 0
     print("HOPE")

end)
1 Like

Thanks bro that worked! nice thanks wow

No problem, my pleasure. char(30)

by the way how would i play a sound while the player is holding the interact prompt? (so like vault door opening sounds or something)

You can use the PromptButtonHoldBegan event.

It will run once you will interact.

thanks bro this helps a lot: very cool