Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This code adds 2 PointLights instead of 1?

When I say ":showlight()" then I get 2 PointLights in my torso instead of 1.

--[Insert the people names that are allowed to use commands in {Admins}.
Owner = {'Player', 'PreyStar'}
Admins = {''}

--[Insert the people names that are not allowed to join the game in {Banned}.
Banned = {'NameHere'}

--[Insert the symbol you want to use before a command is made in {Symbol}.
Symbol = ':'

game.Players.PlayerAdded:connect(function(Plr)
	Plr.CharacterAdded:connect(function(Char)
		Plr.Chatted:connect(function(Msg)
			for i,v in pairs (Banned) do
				if v.Name == (Banned) then
					v:Kick('You are banned from the game.')
				end
			end
		
			for i,v in pairs (Owner) do
				if Msg:lower() == (':help') then
					for i,v in pairs (game.Players:GetPlayers()) do
						v.PlayerGui[':help'].Frame.Visible = true
					end
				end				
				
				if Msg:lower() == (Symbol.. 'ff()') then
					local ff = Instance.new('ForceField')
					ff.Parent = Char
				end
								
				if Msg:lower() == (Symbol.. 'clearall()') then
					game.Workspace:ClearAllChildren()
				end
				
				if Msg:lower() == (Symbol.. 'die()') then
					Char.Humanoid.Health = 0
				end



--THE TROUBLE IS HERE, BELOW!


				if Msg:lower() == (Symbol.. 'showlight()') then
					local Light = Instance.new('PointLight', Char.Torso)
					Light.Range = 15
					Light.Shadows = true
				end
				
				if Msg:lower() == (Symbol.. 'givesword()') then
					local sword = Instance.new("Tool", Plr.Backpack) sword.Name = "Sword"  sword.TextureId = "rbxasset://Textures/Sword128.png"
					sword.GripForward = Vector3.new(-1,0,0)
					sword.GripPos = Vector3.new(0,0,-1.5)
					sword.GripRight = Vector3.new(0,1,0)
					sword.GripUp = Vector3.new(0,0,1)
					local handle = Instance.new("Part", sword) handle.Name = "Handle" handle.FormFactor = "Plate" handle.Size = Vector3.new(1,.8,4) handle.TopSurface = 0 handle.BottomSurface = 0
					local msh = Instance.new("SpecialMesh", handle) msh.MeshId = "rbxasset://fonts/sword.mesh" msh.TextureId = "rbxasset://textures/SwordTexture.png"
					local cl = script.LocalScriptBase:Clone() cl.Parent = sword cl.Code.Value = [[
					repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Humanoid")
					local Damage = 15
					local SlashSound = Instance.new("Sound", script.Parent.Handle)
					SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav"
					SlashSound.Volume = 1
					local LungeSound = Instance.new("Sound", script.Parent.Handle)
					LungeSound.SoundId = "rbxasset://sounds\\swordlunge.wav"
					LungeSound.Volume = 1
					local UnsheathSound = Instance.new("Sound", script.Parent.Handle)
					UnsheathSound.SoundId = "rbxasset://sounds\\unsheath.wav"
					UnsheathSound.Volume = 1
					local last = 0
					script.Parent.Handle.Touched:connect(function(hit)
					if hit and hit.Parent and hit.Parent:findFirstChild("Humanoid") and game.Players:findFirstChild(hit.Parent.Name) and game.Players.LocalPlayer.Character.Humanoid.Health > 0 and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
					local tag = Instance.new("ObjectValue", hit.Parent.Humanoid) tag.Value = plr1 tag.Name = "creator" game:service("Debris"):AddItem(tag, 3)
					hit.Parent.Humanoid:TakeDamage(Damage)
					end
					end)
					script.Parent.Activated:connect(function()
					if not script.Parent.Enabled or game.Players.LocalPlayer.Character.Humanoid.Health <= 0 then return end
					script.Parent.Enabled = false
					local tick = game:service("RunService").Stepped:wait()
					if tick - last <= .2 then
					LungeSound:play()
					local lunge = Instance.new("StringValue", script.Parent) lunge.Name = "toolanim" lunge.Value = "Lunge"
					local frc = Instance.new("BodyVelocity", game.Players.LocalPlayer.Character.Torso) frc.Name = "SwordForce" frc.velocity = Vector3.new(0,10,0)
					wait(.2)
					script.Parent.GripForward = Vector3.new(0,0,1)
					script.Parent.GripRight = Vector3.new(0,-1,0)
					script.Parent.GripUp = Vector3.new(-1,0,0)
					wait(.3)
					frc:Destroy() wait(.5)
					script.Parent.GripForward = Vector3.new(-1,0,0)
					script.Parent.GripRight = Vector3.new(0,1,0)
					script.Parent.GripUp = Vector3.new(0,0,1)
					else
					SlashSound:play()
					local slash = Instance.new("StringValue", script.Parent) slash.Name = "toolanim" slash.Value = "Slash"
					end
					last = tick
					script.Parent.Enabled = true
					end)
					script.Parent.Equipped:connect(function(mouse)
					for i,v in pairs(game.Players.LocalPlayer.Character.Torso:children()) do if v.Name == "SwordForce" then v:Destroy() end end
					UnsheathSound:play()
					script.Parent.Enabled = true
					if not mouse then return end
					mouse.Icon = "http://www.roblox.com/asset/?id=103593352"
					end)]] cl.Disabled = false 
				end
			end
		end)
	end)
end)

4 comments

0

This bit of code isn't enough to tell why two objects are being created.

0

Want me to paste the full admin script? It's 116 lines

0

Okay, may take a bit to figure out what's going on.

0

It's an admin script I am making

1 answer

✓ Accepted answer

Current Problem

It seems that the two objects are being created because of line 20. The for loop on the line will run twice and there isn't any check if the player using the command has the same name as one of the owners. So this is causing it to check the command twice and creates two of your PointLights when chatting once.

There are also other bits of concern in the code.

Lines 12-13

Whenever the character respawns a new Chatted event is created. If someone chats a command after they have respawned this will cause the commands to have their effects on the older dead characters and the current alive one.

Lines 14-18

This code is a bit flawed for checking if the player is banned. Also it is within the Chatted event, so they will only get kicked after they chat.

Line 21

I am a little confused about your help command, since this will cause the gui object to appear for everyone in the game. I would assume it should be for the player that chats the command but I'll leave that up to you to fix since I am unsure of your intentions of the command.

I have changed some things to fix the issues I've seen

--[Insert the people names that are allowed to use commands in {Admins}.
Owner = {'Player', 'PreyStar'}
Admins = {''}

--[Insert the people names that are not allowed to join the game in {Banned}.
Banned = {'NameHere'}

--[Insert the symbol you want to use before a command is made in {Symbol}.
Symbol = ':'

game.Players.ChildAdded:connect(function(Plr)
	for i,v in pairs(Banned) do -- kick the player right as they enter rather than after they have chatted and spawned
		-- v is the name in the table, not the Player
		if Plr.Name == v then -- if v.Name == (Banned) then
			Plr:Kick('You are banned from the game.') -- v:Kick('You are banned from the game.')
			return -- quit the function since the player was kicked
		end
	end
	Plr.Chatted:connect(function(Msg)
		local isOwner = false
		for i,v in pairs(Owner) do -- check if the player is an owner
			if Plr.Name == v then
				isOwner = true
				break
			end
		end
		
		local isAdmin = false
		for i,v in pairs(Admins) do -- check if the player is an admin
			if Plr.Name == v then
				isAdmin = true
				break
			end
		end
		
		local Char = Plr.Character -- getting the Character from a property rather than an event
		
		if isOwner then -- check for Owner only commands (just assuming all commands are owner only)
			if Msg:lower() == (':help') then
				for i,v in pairs (game.Players:GetPlayers()) do
					v.PlayerGui[':help'].Frame.Visible = true
				end
			-- using elseif rather than multiple if statements are more efficient
			elseif Msg:lower() == (Symbol.. 'ff()') then
				local ff = Instance.new('ForceField')
				ff.Parent = Char
			elseif Msg:lower() == (Symbol.. 'clearall()') then
				game.Workspace:ClearAllChildren()
			elseif Msg:lower() == (Symbol.. 'die()') then
				Char.Humanoid.Health = 0
			elseif Msg:lower() == (Symbol.. 'showlight()') then
				local Light = Instance.new('PointLight', Char.Torso)
				Light.Range = 15
				Light.Shadows = true
			elseif Msg:lower() == (Symbol.. 'givesword()') then
				local sword = Instance.new("Tool", Plr.Backpack) sword.Name = "Sword"  sword.TextureId = "rbxasset://Textures/Sword128.png"
				sword.GripForward = Vector3.new(-1,0,0)
				sword.GripPos = Vector3.new(0,0,-1.5)
				sword.GripRight = Vector3.new(0,1,0)
				sword.GripUp = Vector3.new(0,0,1)
				local handle = Instance.new("Part", sword) handle.Name = "Handle" handle.FormFactor = "Plate" handle.Size = Vector3.new(1,.8,4) handle.TopSurface = 0 handle.BottomSurface = 0
				local msh = Instance.new("SpecialMesh", handle) msh.MeshId = "rbxasset://fonts/sword.mesh" msh.TextureId = "rbxasset://textures/SwordTexture.png"
				local cl = script.LocalScriptBase:Clone() cl.Parent = sword cl.Code.Value = [[
				repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Humanoid")
				local Damage = 15
				local SlashSound = Instance.new("Sound", script.Parent.Handle)
				SlashSound.SoundId = "rbxasset://sounds\\swordslash.wav"
				SlashSound.Volume = 1
				local LungeSound = Instance.new("Sound", script.Parent.Handle)
				LungeSound.SoundId = "rbxasset://sounds\\swordlunge.wav"
				LungeSound.Volume = 1
				local UnsheathSound = Instance.new("Sound", script.Parent.Handle)
				UnsheathSound.SoundId = "rbxasset://sounds\\unsheath.wav"
				UnsheathSound.Volume = 1
				local last = 0
				script.Parent.Handle.Touched:connect(function(hit)
				if hit and hit.Parent and hit.Parent:findFirstChild("Humanoid") and game.Players:findFirstChild(hit.Parent.Name) and game.Players.LocalPlayer.Character.Humanoid.Health > 0 and hit.Parent.Humanoid ~= game.Players.LocalPlayer.Character.Humanoid then
				local tag = Instance.new("ObjectValue", hit.Parent.Humanoid) tag.Value = plr1 tag.Name = "creator" game:service("Debris"):AddItem(tag, 3)
				hit.Parent.Humanoid:TakeDamage(Damage)
				end
				end)
				script.Parent.Activated:connect(function()
				if not script.Parent.Enabled or game.Players.LocalPlayer.Character.Humanoid.Health <= 0 then return end
				script.Parent.Enabled = false
				local tick = game:service("RunService").Stepped:wait()
				if tick - last <= .2 then
				LungeSound:play()
				local lunge = Instance.new("StringValue", script.Parent) lunge.Name = "toolanim" lunge.Value = "Lunge"
				local frc = Instance.new("BodyVelocity", game.Players.LocalPlayer.Character.Torso) frc.Name = "SwordForce" frc.velocity = Vector3.new(0,10,0)
				wait(.2)
				script.Parent.GripForward = Vector3.new(0,0,1)
				script.Parent.GripRight = Vector3.new(0,-1,0)
				script.Parent.GripUp = Vector3.new(-1,0,0)
				wait(.3)
				frc:Destroy() wait(.5)
				script.Parent.GripForward = Vector3.new(-1,0,0)
				script.Parent.GripRight = Vector3.new(0,1,0)
				script.Parent.GripUp = Vector3.new(0,0,1)
				else
				SlashSound:play()
				local slash = Instance.new("StringValue", script.Parent) slash.Name = "toolanim" slash.Value = "Slash"
				end
				last = tick
				script.Parent.Enabled = true
				end)
				script.Parent.Equipped:connect(function(mouse)
				for i,v in pairs(game.Players.LocalPlayer.Character.Torso:children()) do if v.Name == "SwordForce" then v:Destroy() end end
				UnsheathSound:play()
				script.Parent.Enabled = true
				if not mouse then return end
				mouse.Icon = "http://www.roblox.com/asset/?id=103593352"
				end)]] cl.Disabled = false 
			end
		end
		
		if isOwner or isAdmin then -- check for Owner and Admin only commands (if there are any)
		end
		
		-- check for commands that anyone can use after this line (if there are any)
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.