ProximityPrompt Won't Enable when item(s) are equipped

I’m trying to get a ProximityPrompt to become enabled if the player possesses the correct tool (In this case any form of seeds)

The seeds are correctly functioning in a number system.
1 = Strawberries,
2 = Carrots
etc. All the triggers (Such as Booleans and Number Values and regulate how many times you can use the seeds to keeping track of what type of seeds you have). The issue is that the Proximity prompt isn’t responding to my while loop. I was trying to get it to become enabled if any of the numbers within the “SeedNumber” folder is higher than 0. ie 1+.

The script isn’t in charge of what to do with the seeds, but just to simply check if you, the player are holding a seeds pack that is anywhere but over 0. If I made sense.

script: (Please note I am not receiving any errors of any kind, the scripts are all server scripts. Only local script is within the tool for any and all seeds).

while wait(.05) do
	local Folder = game.Workspace.Triggers.SeedRelated.EquippedSeeds for _,v in pairs(Folder:GetChildren()) do
		local SeedNumber = game.Workspace.Triggers.SeedRelated.SeedNumber
		if SeedNumber.Value >= 1 then
			script.Parent.Enabled = true
		end
		if SeedNumber.Value == 0 then
			script.Parent.Enabled = false
		end
	end
end

Im no pro coder so Im sure my method above is probably wrong. Any help is appreciated :slight_smile:

Why is the variable Folder and a for loop is on the same line?

Wouldn’t they need to be in that order in order for the rest of the script to read through the Folder’s children?

Also, Instead of using a While loop in a Value changing object. Use the GetPropertyChangedSignal() instead so it will only runs when a selected Property has changed its value or something.

It will like this:

local money = script.Parent:WaitForChild("Money")

money:GetPropertyChangedSignal("Value"):Connect(function() -- Will run if the Value is changed.
    print("Money changed its value to: ", money.Value)
end)

I mean, look at this this will get an error.

local Folder = game.Workspace.Triggers.SeedRelated.EquippedSeeds for _,v in pairs(Folder:GetChildren()) do

Something like this? I mean it doesn’t work but as long as I’m on the right track lol

local SeedNumber = game.Workspace.Triggers.SeedRelated.SeedNumber

SeedNumber:GetPropertyChangeSignal("Value"):Connect(function()
	if SeedNumber.Value >= 1 then
		script.Parent.Enabled = true
	end

	if SeedNumber.Value == 0 then
		script.Parent.Enabled  = false
	end
end)
1 Like

Use elseif in this code since they are referring to a same variable:

if SeedNumber.Value >= 1 then
	script.Parent.Enabled = true
elseif SeedNumber.Value == 0 then
	script.Parent.Enabled  = false
end

So, what type of script does the SeedNumber’s Value handles?

The script itself is a server script. (Simple blue page). The core function of the script is to continuously check if the Seed Number (Because every type of produce is logged with a certain number). Is 1 or higher. If its 1 or higher it’ll enable the functionality of the Proximity Prompt. I did learn in the past few minutes through you, and my own tweaking, it doesn’t matter if its 1, 2, 3 (Strawberries, Carrots etc). Just as long as it’s 1 or higher.

Sorry, that was my error, I thought I’d need to for loop the contents of the folder :frowning:

The script your referring to is the Changing value event itself. What I mean is who/what is the one who manage to change the value of the SeedNumber?

Is it coming from the localsript or script?

It’s a script. As if I was to file > Insert > Script nothing fancy :slight_smile:

When a tool (Carrot Seed Pack etc) is equipped It will change the SeedNumber to the correct number for that seed type. (2, in this case), the who is the player who receives that tool.

Mind if you paste the code in here? I can’t understand some of the explanation.

Sure, I’ll paste everything I can think that relates to the problem :smiley:

This is the Strawberry Seeds Script. Its a Local script within a tool.

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid")
local anim = h:LoadAnimation(script.Parent:WaitForChild("Idle"))
local anim2 = h:LoadAnimation(script.Parent:WaitForChild("Clicked"))
local tool = script.Parent
local StrawberrySeedsSelected = workspace.Triggers.SeedRelated.EquippedSeeds.StrawberrySeedsSelected

local StrawberrySeedNumber = game.Workspace.Triggers.SeedRelated.SeedNumber

local SeedAmountPerPack = 6

tool.Equipped:Connect(function()
     anim:Play()
     StrawberrySeedsSelected.Value = true
     StrawberrySeedNumber.Value = 1
end)

tool.Unequipped:Connect(function()
     StrawberrySeedsSelected.Value = false
     StrawberrySeedNumber.Value = 0
     anim:Stop()
     anim2:Stop()
end)

tool.Activated:Connect(function()
     SeedAmountPerPack = SeedAmountPerPack - 1
          if SeedAmountPerPack == 0 then
               wait(.75)
               script.Parent:Destroy()
          end
     h.WalkSpeed = 0
     anim2:Play()
     wait(.75)
     h.WalkSpeed = 16
end)

This is the revised script for the SeedNumber checker. Its a Script. child of the ProximityPrompt.

local SeedNumber = game.Workspace.Triggers.SeedRelated.SeedNumber

SeedNumber:GetPropertyChangeSignal("Value"):Connect(function()
	if SeedNumber.Value >= 1 then
		script.Parent.Enabled = true
	elseif SeedNumber.Value == 0 then
		script.Parent.Enabled = false
	end
end)

Yep, I knew the problem now…

Since, the Localscript only works on the client-side, the Script that handles the changing value of SeedNumber is not getting some changing value because the Script is on the server-sided.

To fix this, use a RemoteEvent to change the SeedNumber value on the server so that the function for the value of SeedNumber when changed will run.

1 Like

Another solution is adding a Script inside the tool. it will work the same and you will not use a RemoteEvents at all.

Just copy the scripts in the Localscript that handles the Tool.~ events and paste it to the Script

1 Like

I’ll have to look into the RemoteEvents because they confuse me a bit lol. However I did move all the contents of the local script to a script. Works alright; only issue is the animations and changes to the WalkSpeed are broken. But if I remove ( " – " ) them it works like you said. It becomes enabled.

1 Like

So, the ProximityPrompt works now?

If so, you may close this topic as Solved

Glad I helped you!

1 Like

Of course! Thank you so much! I am grateful! :smiley:

Since the line of code that handles the Walkspeed is on the localscript, you can just remove it from the script since the purpose of the script is to change the value of SeedNumber only.