Need help with making a script

Im attempting to make a script where only 1 team can pick up an item by holding the proximity prompt on a model, in which the model regens over time after picking it up,
Im not able to find any tutorials on how to do this so, im looking for answers on the devforum.

I only have print()
and wait() currently, and its my first time ever making a script so im really confused right now.
Can anyone help me?

Well, we can’t just make the script for you. But we certainly can help you get started!

  1. Firstly, lets break down the problem. There are a few steps to this.
  • Checking if a player has used the proximity prompt.
  • If they have used it, check if they are on the right team
  • (If they are on the right team, proceed. If not, do nothing or show a GUI saying that they aren’t eligible to pick it up)
  • If they can pick it up, give them the tool.
  • Then, initiate a server-wide cooldown so that the next person has to wait before picking it up (is this what you mean by “in which the model regens over time after picking it up”?)
  1. Then, we look for ways to do each of these things 1 by 1. First, since we want this to happen for all players, lets use a Server Script for this. Then, we use ProximityPrompt.PromptTriggered to see if the prompt has been triggered and pass on the player parameter to get the player object (so we can see who has triggered it).
    Next, we need to check if they are on the right team. We can do so by saying
if player.team == game:GetService("Teams").TeamName

If they are, lets give them the tool by cloning it (using :Clone)and setting it’s parent to Player.Character (the player’s character)
Then, we have to disable the prompt by setting the Enabled property of proximity prompts to false and use task.wait(cooldown) so that no further players will be able to use the prompt until the timer is up. Once it is, we can enable it again.
I hope this helps in some way - let me know if you need any help.

1 Like

Took me 10 min to script and test if it works nice, and it does. If you want me to explain what each do let me know. Hope this script and teach you how to script a simple prompt regen tool.

--Variables ...
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local prompt = handle:FindFirstChild("ProximityPrompt")

local regenTime = 10 --seconds to regen
local pickUp = true  --to tell if the item is pickable or not, to start with it's true (pickable)

for i, v in pairs(script.Parent:WaitForChild("Handle"):GetChildren()) do --here we clear the touchInterest to make the tool not pickable from touch.
	if v.Name == "TouchInterest" then
		v:Destroy()
		print(v.Name.." got destroyed")
	end
end

local function regen() --regen function, whenever a player picks up the item, we'll call it to regen after regenTime seconds, and also to make the count gui above the tool visible when start to count and no visible when count hits 0
	if pickUp == false then --if pickup is false which means the player picked up the item and we need to make it not pickable after some seconds then..
		for i = regenTime, 0, -1 do 
			handle.BillboardGui.CountText.Visible = true
			handle.BillboardGui.CountText.Text = i
			
			if i == 0 then
				pickUp = true --when count reaches 0, we'll tell that the item is able to be picked up again.
				handle.BillboardGui.CountText.Visible = false --and also set the count gui visibility to false
			end
			
			task.wait(1)--each second it counts -1
			print(i)
		end
	end
	
end


local function PickUp(playerWhoTriggered) --pickup function
	if pickUp then-- if pickable means if pickUp == true
		if playerWhoTriggered.Team.Name == "Blue" then --check player team, we want only blue to piclup
			local clonedTool = tool:Clone()-- clone it and move to player's backpack, and clean it from the prompt and count gui.
			clonedTool.Handle.Anchored = false
			clonedTool.Parent = playerWhoTriggered.Backpack
			clonedTool.Handle.ProximityPrompt:Destroy()
			clonedTool.Handle.BillboardGui:Destroy()
			pickUp = false --we tell that the item is no longer pickable
			regen()--call the regen function to make the item pickable after some seconds
		else --means player is not in blue team
			print("player is not in team Blue!")
			return 
		end
	else -- means the pickUp is false and is on delay to be pickUp to true
		print("Wait "..handle.BillboardGui.CountText.Text.." seconds.")
		return 
	end
	
end

prompt.Triggered:Connect(PickUp) --connect it to the PickUp function, a good habit. Don't always create anonymouse functions

Edit* Added comments explaining what each line does.

Cool script but we sort of aren’t really meant to just hand feed them the script. This person seems to be a new scripter, and they most likely won’t understand most of this. It’d be best to help them understand this code with some comments too.

Yes, I said in post if he needs any explanation I’ll explain the script. I learned a lot like this, so I help people this way. I get a script and spend some nice time learning how the script works…

Alrighty, thanks.

charscharschars stupid chars rule