Trying to change a proximity prompts text when clicked

image now it says this

Change CFrameCFrame to CFrame.

well u used the same code as me.u just changed “on” to “toggle” and set it to top

Hold on I am going to revise the code again.

thanks ill fix that now :slight_smile:

If it works, mark one of these as a solution.

There, I revised the code:

local Hinge = script.Parent.PrimaryPart
local opened = false

local prompt = script.Parent.Door.ProximityPrompt


function OpenDoor()
	if opened == false then
		opened = true
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
		prompt.ActionText = "Close Door" 
	else
		opened = false
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
		prompt.ActionText = "Open Door"
	end
end

prompt.Triggered:Connect(OpenDoor)

That’s better code, hope I helped!

1 Like

image

That won’t work, you have to reference CFrame.Angles as a constructor instead & not a position

local Hinge = script.Parent.PrimaryPart
local opened = false

local prompt = script.Parent.Door.ProximityPrompt


function OpenDoor()
	if opened == false then
		opened = true
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
		prompt.ActionText = "Close Door" 
	else
		opened = false
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
		prompt.ActionText = "Open Door"
	end
end

prompt.Triggered:Connect(OpenDoor)

Also you didn’t connect the function like @AridFights1 mentioned

Now the door doesnt open sigh :thinking:

local Hinge = script.Parent.PrimaryPart
local opened = false

local prompt = script.Parent.Door.ProximityPrompt


function OpenDoor()
	if opened == false then
		opened = true
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
		prompt.ActionText = "Close Door" 
	else
		opened = false
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
		prompt.ActionText = "Open Door"
	end
end

thats the code i got

You forgot this part. Put this at the bottom:

prompt.Triggered:Connect(OpenDoor)
1 Like

Before what code you used for opening and closing the door just use that.

Edit: Sorry for replying to wrong person.

door still dont open i have no idea

I think I know why. I’ve been experimenting for a while. This should work:

local Hinge = script.Parent.PrimaryPart
local opened = false

local prompt = script.Parent.ProximityPrompt

function OpenDoor()
	if opened == false then
		opened = true
		prompt.ActionText = "Close Door" 
		for i = 0, 5, 0.1 do
			Hinge.CFrame = Hinge.CFrame*CFrame.Angles(0, math.rad(i), 0)
			wait(0.01)
		end
		
	elseif opened == true then
		opened = false
		prompt.ActionText = "Open Door"
		for i = 0, -5, -0.1 do
			Hinge.CFrame = Hinge.CFrame*CFrame.Angles(0, math.rad(i), 0)
			wait(0.01)
		end	
	end
end

prompt.Triggered:Connect(OpenDoor)

well it changes now but the door wont open

local prompt = -- path to proximityprompt
local defaultText = prompt.ActionText

local opened = false

prompt.Triggered:Connect(function()
    opened = not opened
	prompt.ActionText = opened and defaultText or 'Close the door'
end)

Any errors in the output?-----