Include a standalone, bare-bones rbxl file with only the code you want reviewed.
- Code Review is for reviewing specific parts of your code, and not your whole game.
- Code Review is intended for improving already-working code. If you need help debugging your code, please use Scripting Support.
Provide an overview of:
-
What does the code do and what are you not satisfied with?
My code checks if the player has other parts in the radius when the touch ends and if they don’t, it sets their StrAreaMulti to 1.
I want to know if there is a better way I didn’t think of to do that. -
How (specifically) do you want to improve the code?
I want the code to be more efficient.
Script:
local OPT
local Part = script.Parent
local biggestDimension=Part.Size.Magnitude/2
local DetectionRadius=Instance.new("Part")
DetectionRadius.Parent=Part.Parent
DetectionRadius.Shape=Enum.PartType.Ball
DetectionRadius.Size=Vector3.new(biggestDimension*2,biggestDimension,biggestDimension)
DetectionRadius.Position=Part.Position
DetectionRadius.Transparency=0.8
DetectionRadius.CanCollide=false
DetectionRadius .Anchored=true
DetectionRadius.Touched:Connect(function (hit)
if hit.Parent:FindFirstChild('Humanoid') then
local PlayerFromTouch = game.Players[hit.Parent.Name]
PlayerFromTouch:WaitForChild('OV').StrAreaMulti.Value = 2
end
end)
function CheckPartFOTP(hit)
local player=game.Players:GetPlayerFromCharacter(hit.Parent)
for i,v in pairs(hit.Parent:GetChildren()) do
local OtherPartTouching=table.find(game.Workspace:GetPartsInPart(DetectionRadius),v)
if OtherPartTouching~=nil then
OPT=true
break
else
OPT=nil
end
end
return OPT
end
function SetMulti(hit)
local player=game.Players:GetPlayerFromCharacter(hit.Parent)
if player:DistanceFromCharacter(Part.Position) > biggestDimension and OPT == nil then
player:WaitForChild('OV').StrAreaMulti.Value = 1
end
end
DetectionRadius.TouchEnded:Connect(function(hit)
if not hit.Parent:FindFirstChild('Humanoid') or hit.Parent.Parent:FindFirstChild('Humanoid')then
return
end
local player=game.Players:GetPlayerFromCharacter(hit.Parent)
wait(1)
CheckPartFOTP(hit)
SetMulti(hit)
end)