Modify cola script

i have a promxityprompt script, but the problem is I only want the player to have one…how do I mod my script to do that?
the script:

local ProximityPrompt = script.Parent.ProximityPrompt

ProximityPrompt.Triggered:Connect(function(Player)
    local copy = game.ReplicatedStorage["Cola"]:Clone()
	copy.Parent = Player.Backpack
	
	
	end)
local ProximityPrompt = script.Parent.ProximityPrompt

ProximityPrompt.Triggered:Connect(function(Player)
	if Player.Backpack:FindFirstChild("Cola") =~ nil then
		local copy = game.ReplicatedStorage["Cola"]:Clone()
		copy.Parent = Player.Backpack
	
	
	end)

I think this will work, I basically added if Cola isn’t found in the player’s backpack, then put it in their backpack.

there is error here ;-;

The problem is actually that you guys have forgotten to close the if statement! All you need to do is add an “end” before the “end)” on the last line:

local ProximityPrompt = script.Parent.ProximityPrompt

ProximityPrompt.Triggered:Connect(function(Player)
	if Player.Backpack:FindFirstChild("Cola") =~ nil then
		local copy = game.ReplicatedStorage["Cola"]:Clone()
		copy.Parent = Player.Backpack
	end	
end)

Oh yeah, I didn’t realize that.

1 Like

and this?

I think you need to do this

local ProximityPrompt = script.Parent.ProximityPrompt

ProximityPrompt.Triggered:Connect(function(Player)
	if Player.Backpack:FindFirstChild("Cola") ~= nil then
		local copy = game.ReplicatedStorage["Cola"]:Clone()
		copy.Parent = Player.Backpack
	end	
end)

huh when i use the prompt it gave me nothing

ima try make this ==…it might work I guess

Try this then

ProximityPrompt.Triggered:Connect(function(Player)
	if Player.Backpack:FindFirstChild("Cola") == nil then
		local copy = game.ReplicatedStorage["Cola"]:Clone()
		copy.Parent = Player.Backpack
	end	
end)
1 Like

all i had to do was make the ~= ==