Help With Aiming Script for Multiple brickbattle weapons

  1. What do you want to achieve? A script that detects if the player is in the radius.

  2. What is the issue? Cannot find how to make it detect if the player is there

  3. What solutions have you tried so far? Looked on the toolbox and the forums and couldn’t find anything. I tried out the script below, but it doesn’t work well and lags alot. This was just a concept to see if my script could atleast detect the player moving in and out of the field.

 script.Parent.Touched:Connect(function(part)
	if part.Parent:IsA("Model") and part.Parent.PrimaryPart ~= part then
		print("no")
	end
	if part.Parent:FindFirstChild("Humanoid") then
		local plrname = part.Parent.Name
		local plrObj = game.Players:FindFirstChild(plrname)
		if plrObj ~= nil then
			local targetting = true
			while targetting == true do
				wait()
				print("targetting!")
				script.Parent.TouchEnded:Connect(function(part2)
					local plrname2 = part2.Parent.Name
					local plrObj2 = game.Players:FindFirstChild(plrname2)
					if part2.Parent:IsA("Model") and part2.Parent.PrimaryPart ~= part2 then
						print("no")
					else
						targetting = false
						wait(2)
					end
					
				end)
			end
		end
	end
end)

I would appreciate someone to point out the issues in this script, as it is my first time trying this. Thanks.

local part = script.Parent
local playersInArea = {}

local function onTouch(part)
    local playerModel = part.Parent
    if playerModel:IsA("Model") and playerModel:FindFirstChild("Humanoid") then
        local playerName = playerModel.Name
        if not playersInArea[playerName] then
            playersInArea[playerName] = true
            print(playerName .. " has entered the area!")
        end
    end
end

local function onTouchEnded(part)
    local playerModel = part.Parent
    if playerModel:IsA("Model") and playerModel:FindFirstChild("Humanoid") then
        local playerName = playerModel.Name
        if playersInArea[playerName] then
            playersInArea[playerName] = nil
            print(playerName .. " has exited the area!")
        end
    end
end

part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
1 Like

Thanks, seems to work just fine! :+1:

2 Likes

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