ProximityPrompt Tool

I have tools in ReplicatedStorage and to grab them I added copies of the Handle in Workspace with ProximityPrompt, everything works fine but when I added a “random spawn script”, the spawn script works correctly although the ProximityPrompt doesn’t work when the part is randomly spawned.

Random spawn script:

local Rspawn = game.Workspace.RedSpawns:GetChildren()  --Folder location and name
local Bspawn = game.Workspace.BlueSpawns:GetChildren()
local Gspawn = game.Workspace.GreenSpawns:GetChildren()

local Rcube = game.ServerStorage.blocks:FindFirstChild("Red Cube")
local Bcube = game.ServerStorage.blocks:FindFirstChild("Blue Cube")
local Gcube = game.ServerStorage.blocks:FindFirstChild("Green Cube")



function SpawnItem()
	
	local newItem = Rcube:Clone()
	local ItemSpawn = Rspawn[math.random(1, #Rspawn)]
	newItem.CFrame = ItemSpawn.CFrame
	newItem.Parent = workspace
	wait(0)
	local newItem = Bcube:Clone()
	local ItemSpawn = Bspawn[math.random(1, #Bspawn)]
	newItem.CFrame = ItemSpawn.CFrame
	newItem.Parent = workspace
	wait(0)
	local newItem = Gcube:Clone()
	local ItemSpawn = Gspawn[math.random(1, #Gspawn)]
	newItem.CFrame = ItemSpawn.CFrame
	newItem.Parent = workspace
	
	
		
	
	
	
end

	SpawnItem()


ProximityPrompt script:

local Tool = game.ReplicatedStorage.Cubes:WaitForChild("Red Cube")
local prox = Instance.new("ProximityPrompt")
local ball = script.Parent 
prox.Parent = ball
prox.ObjectText = "Red Cube"
prox.ActionText = "Take"
prox.MaxActivationDistance = 4

local function onPromptTriggered(plr)

	if plr.Character:FindFirstChild("Red Cube") or plr.Backpack:FindFirstChild("Red Cube") then
	
		return
	else
		local ToolClone = Tool:Clone()
		ToolClone.Parent = plr.Backpack
	end
end

prox.Triggered:Connect(onPromptTriggered)

I tried messing with the ProximityPrompt Properties and of course there’s two scripts idk which one would need an edit, help please!

1 Like

I edited on the Propmt script, I added the RequiresLineOfSight = false and it worked.

1 Like

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