How to go about making a script that enables and disables a Fire Part using a Proximity Prompt

Hi everyone, I’ve recently been creating my own game (a semi-rp wolf game) but I’m having trouble with creating a functional script that enables and disables my fire part whilst using a Proximity Prompt to trigger the script (my aim was for the player to hold F on the Fireplace Asset and then the fire will turn on/off when the player does this.)

I was given a script to use but it hasn’t been working, not sure if it’s something to do with where the script is placed or if it just doesn’t work anymore but when using the Proximity Prompt it doesn’t turn the fire on or off. It just does nothing. The script I’ve input is as follows:

local fire = workspace:WaitForChild("FirePart").Fire -- LOCAL SCRIPT IN STARTERPLAYERSCRIPTS (ONLY PLAYER CAN SEE)
local prox = workspace.FirePart.ProximityPrompt

prox.Triggered:Connect(function()
	if fire.Enabled == true then
		fire.Enabled = false
	else
		fire.Enabled = true
	end
end)

Here is also an image of where I’ve placed the script. The fireplace asset with the Fire Part in it is in Workspace.
Screenshot 2023-12-09 192015

Solutions wise I have searched both YouTube, here and tried asking for assistance in Discord servers but none of them have worked.

3 Likes

Hello! Is the fire part already in the workspace to begin with or does a player summon it?
Also a simplified script for this is:

local fire = workspace:WaitForChild("FirePart").Fire
local prox = workspace.FirePart.ProximityPrompt

prox.Triggered:Connect(function()
	fire.Enabled = not fire.Enabled
end)
2 Likes

Yes, the Fire Part is already in Workspace but it’s inside of my Fireplace asset/model which I was thinking maybe that was where the issue is but not sure. Also, I will go ahead and adjust the script to what you suggested now and see if that works!

1 Like

Okay. Are you able to send an image of the explorer so I can see what your fire asset looks like?

2 Likes

Yep, here! Also just tried changing the script to that and still won’t function, really not sure what’s causing this.
Screenshot 2023-12-09 195757

2 Likes

Try changing the script to:

local fireplaceAsset = workspace:WaitForChild("FireplaceAsset")
local fire = asset:WaitForChild("FirePart").Fire
local prox = asset.ProximityPrompt

prox.Triggered:Connect(function()
	fire.Enabled = not fire.Enabled
end)

I believe the problem is that you were trying to access the firepart from the workspace, but it is parented to fireplaceasset, which contains the firepart and the proximity prompt.

2 Likes

Okay, does the Fire Part itself need to be enabled first btw?

1 Like

Although just tried with it disabled and enabled and still isn’t doing anything for some reason.

1 Like

Wait, I found the problem, needed to change the asset part of the script you provided but it’s all working now, will only the player who has enabled the fire be able to see it though or will it be every player?

Also thank you for your help!

2 Likes

since it is a local script, only the person who enabled it will see it

2 Likes

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