- What do you want to achieve?
I want to make my code more efficient. A simple glowband place script that allows the server to see. Has color changing, and certain welds. Already achieved most of the code.
- What is the issue?
Problem is I don’t know the best way to achieve a simple glow band script.
Also noticed that mine doesn’t have the way of checking if the player has a glowband on already, and if so to update the color if needed. Also the glowbands are being mass produced when their should only be 4 per a person.
- What solutions have you tried so far?
Tried thinking of checking
if plr.Character:FindFirstChild("GLOWBAND") then
like that type of stuff.
Here is the full code →
--[[
@author TwinPlayzDev_YT
@since 5/26/2021
This script basically handles the events, and places a glowband on a player.
--]]
-- [[ SERVICES ]] --
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- replicated
local ServerStorage = game:GetService("ServerStorage") -- server storage
local MarketPlaceService = game:GetService("MarketplaceService") -- marketplace
-- [[ EVENT LOCALS ]] --
local GlowBandEvents = ReplicatedStorage.EVENTS:WaitForChild("GlowBandEvents") -- glow band event folder
local LeftArmEvent = GlowBandEvents.LeftArmEvent -- left arm
local LeftLegEvent = GlowBandEvents.LeftLegEvent -- left leg
local RightArmEvent = GlowBandEvents.RightArmEvent -- right arm
local RightLegEvent = GlowBandEvents.RightLegEvent -- right leg
-- [[ GLOWBAND LOCAL ]] --
local GlowBand = ServerStorage:WaitForChild("GlowBandPart") -- Getting The GlowBand Part
local BloxGlowBand = ServerStorage:WaitForChild("BloxGlowBand") -- Getting The GlowBand Part
-- [[ EVENT FUNCTIONS ]] --
-- LEFT
LeftArmEvent.OnServerEvent:Connect(function(plr,val)
local Character = plr.Character -- Grabbing The Player's Character
if Character:FindFirstChild("Yes") then
local LeftArm = Character:FindFirstChild("Left Arm") -- Grabbing The Left Arm
local newLAGlowBand = BloxGlowBand:Clone() -- Making a new glowband
newLAGlowBand.Parent = workspace.GlowParts -- Setting parent to workspace inside glow part folder to see it
newLAGlowBand.CFrame = LeftArm.CFrame -- Setting position/cframe to LeftArm
local BandWeld = Instance.new("WeldConstraint") -- Creating a weld
BandWeld.Part0 = LeftArm -- Weld To Arm
BandWeld.Part1 = newLAGlowBand -- Weld Band To Arm
BandWeld.Parent = LeftArm -- Setting Band Weld Parent To Arm
newLAGlowBand.BrickColor = BrickColor.new(val)
else
local LeftArm = Character.LeftUpperArm -- Grabbing The Left Arm
local newLAGlowBand = GlowBand:Clone() -- Making a new glowband
newLAGlowBand.Parent = workspace.GlowParts -- Setting parent to workspace inside glow part folder to see it
newLAGlowBand.CFrame = LeftArm.CFrame -- Setting position/cframe to LeftArm
local BandWeld = Instance.new("WeldConstraint") -- Creating a weld
BandWeld.Part0 = LeftArm -- Weld To Arm
BandWeld.Part1 = newLAGlowBand -- Weld Band To Arm
BandWeld.Parent = LeftArm -- Setting Band Weld Parent To Arm
newLAGlowBand.BrickColor = BrickColor.new(val)
end
end)
LeftLegEvent.OnServerEvent:Connect(function(plr,val)
local Character = plr.Character -- Grabbing The Player's Character
if Character:FindFirstChild("Yes") then
local LeftLeg = Character:FindFirstChild("Left Leg") -- Grabbing The Left Leg
local newLLGlowBand = BloxGlowBand:Clone() -- Making a new glowband
newLLGlowBand.Parent = workspace.GlowParts -- Setting parent to workspace inside glow part folder to see it
newLLGlowBand.CFrame = LeftLeg.CFrame -- Setting position/cframe to LeftLeg
local BandWeld = Instance.new("WeldConstraint") -- Creating a weld
BandWeld.Part0 = LeftLeg -- Weld To Leg
BandWeld.Part1 = newLLGlowBand -- Weld Band To Leg
BandWeld.Parent = LeftLeg -- Setting Band Weld Parent To Arm
newLLGlowBand.BrickColor = BrickColor.new(val)
else
local LeftLeg = Character.LeftLowerLeg -- Grabbing The Left Leg
local newLLGlowBand = GlowBand:Clone() -- Making a new glowband
newLLGlowBand.Parent = workspace.GlowParts -- Setting parent to workspace inside glow part folder to see it
newLLGlowBand.CFrame = LeftLeg.CFrame -- Setting position/cframe to LeftLeg
local BandWeld = Instance.new("WeldConstraint") -- Creating a weld
BandWeld.Part0 = LeftLeg -- Weld To Leg
BandWeld.Part1 = newLLGlowBand -- Weld Band To Leg
BandWeld.Parent = LeftLeg -- Setting Band Weld Parent To Arm
newLLGlowBand.BrickColor = BrickColor.new(val)
end
end)
-- RIGHT
RightArmEvent.OnServerEvent:Connect(function(plr,val)
local Character = plr.Character -- Grabbing The Player's Character
if Character:FindFirstChild("Yes") then
local RightArm = Character:FindFirstChild("Right Arm") -- Grabbing The Right Arm
local newRAGlowBand = BloxGlowBand:Clone() -- Making a new glowband
newRAGlowBand.Parent = workspace.GlowParts -- Setting parent to workspace inside glow part folder to see it
newRAGlowBand.CFrame = RightArm.CFrame -- Setting position/cframe to RightArm
local BandWeld = Instance.new("WeldConstraint") -- Creating a weld
BandWeld.Part0 = RightArm -- Weld To Arm
BandWeld.Part1 = newRAGlowBand -- Weld Band To Arm
BandWeld.Parent = RightArm -- Setting Band Weld Parent To Arm
newRAGlowBand.BrickColor = BrickColor.new(val)
else
local RightArm = Character.RightUpperArm -- Grabbing The Right Arm
local newRAGlowBand = GlowBand:Clone() -- Making a new glowband
newRAGlowBand.Parent = workspace.GlowParts -- Setting parent to workspace inside glow part folder to see it
newRAGlowBand.CFrame = RightArm.CFrame -- Setting position/cframe to RightArm
local BandWeld = Instance.new("WeldConstraint") -- Creating a weld
BandWeld.Part0 = RightArm -- Weld To Arm
BandWeld.Part1 = newRAGlowBand -- Weld Band To Arm
BandWeld.Parent = RightArm -- Setting Band Weld Parent To Arm
newRAGlowBand.BrickColor = BrickColor.new(val)
end
end)
RightLegEvent.OnServerEvent:Connect(function(plr,val)
local Character = plr.Character -- Grabbing The Player's Character
if Character:FindFirstChild("Yes") then
local RightLeg = Character:FindFirstChild("Right Leg") -- Grabbing The Right Leg
local newRLGlowBand = BloxGlowBand:Clone() -- Making a new glowband
newRLGlowBand.Parent = workspace.GlowParts -- Setting parent to workspace inside glow part folder to see it
newRLGlowBand.CFrame = RightLeg.CFrame -- Setting position/cframe to Right Leg
local BandWeld = Instance.new("WeldConstraint") -- Creating a weld
BandWeld.Part0 = RightLeg -- Weld To Right Leg
BandWeld.Part1 = newRLGlowBand -- Weld Band To Right Leg
BandWeld.Parent = RightLeg -- Setting Band Weld Parent To Right Leg
newRLGlowBand.BrickColor = BrickColor.new(val)
else
local RightLeg = Character.RightLowerLeg -- Grabbing The Right Leg
local newRLGlowBand = GlowBand:Clone() -- Making a new glowband
newRLGlowBand.Parent = workspace.GlowParts -- Setting parent to workspace inside glow part folder to see it
newRLGlowBand.CFrame = RightLeg.CFrame -- Setting position/cframe to Right Leg
local BandWeld = Instance.new("WeldConstraint") -- Creating a weld
BandWeld.Part0 = RightLeg -- Weld To Right Leg
BandWeld.Part1 = newRLGlowBand -- Weld Band To Right Leg
BandWeld.Parent = RightLeg -- Setting Band Weld Parent To Right Leg
newRLGlowBand.BrickColor = BrickColor.new(val)
end
end)
Its a little big and messy, as I have to characters the glowbands are being put on.