Having issues with a smite command

I tried to test it on another person, but the command kept going on me and never went on them.

How do I fix this?

local Prefix = "+"

local RS = game:GetService("ReplicatedStorage")

local BadgeService = game:GetService("BadgeService")

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if player.Name == "NubblyFry" then
			local Players = game:GetService("Players")

			-- List of valid cmds
			local commandsList = {
				"smite"
			}

			local commandMessage = message

			-- Get the first character of the message
			local commandCharacter = string.sub(commandMessage, 1, 1)

			-- Is cmd character valid?
			if commandCharacter == "+" then
				-- Gets the list of words in commandMessage. sub is used to ignore cmd character
				local commandDetails = string.split(string.sub(commandMessage, 2, -1), " ")

				-- Name of command
				local commandName = commandDetails[1]

				-- Name of player
				local playerName = commandDetails[2]

				-- Is name of player and name of command valid?
				if table.find(commandsList, commandName) and Players:FindFirstChild(playerName) then
					local SmiteBlock = RS:WaitForChild("commandObjects"):WaitForChild("Smite"):Clone()
					SmiteBlock.Parent = game.Workspace

					local PlayerObject = Players:FindFirstChild(playerName)

					local character = player.Character

					local ThunderSound = Instance.new("Sound", game.Workspace)
					ThunderSound.SoundId = "rbxassetid://357559831"

					ThunderSound:Play()
					SmiteBlock.Transparency = 1
					
					task.wait(1)
					
					SmiteBlock.Transparency = 0

					SmiteBlock.Position = character:WaitForChild("HumanoidRootPart").Position
					
					local Fire = RS:WaitForChild("Effects"):WaitForChild("Fire"):Clone()
					Fire.Parent = character:WaitForChild("HumanoidRootPart")
					
					BadgeService:AwardBadge(player.UserId, 2125214032)
					
					for i, v in pairs(character:GetChildren()) do
						if v:IsA("Part") or v:IsA("UnionOperation") then
							v.Color = Color3.new(0,0,0)
						end
					end

					task.wait(0.2)

					SmiteBlock:Destroy()
				end
			end
		end
	end)
end)
1 Like

Hey StarJ3M, I hope it’s not too late to help you with this, but it’s just a small oversite.

I see you got the players name into the playerName :+1:

And you also got the Player from Players

But the reason you keep on smiting yourself when you do the command is because you made the target character your character here.

When you should have

local character = PlayerObject.Character

Just wanted to lay it all down so you understood the issue and learned to hopefully not do it again next time. Tbh this happens to me all the time too lol

local Prefix = "+"

local RS = game:GetService("ReplicatedStorage")

local BadgeService = game:GetService("BadgeService")

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if player.Name == "NubblyFry" then
			local Players = game:GetService("Players")

			-- List of valid cmds
			local commandsList = {
				"smite"
			}

			local commandMessage = message

			-- Get the first character of the message
			local commandCharacter = string.sub(commandMessage, 1, 1)

			-- Is cmd character valid?
			if commandCharacter == "+" then
				-- Gets the list of words in commandMessage. sub is used to ignore cmd character
				local commandDetails = string.split(string.sub(commandMessage, 2, -1), " ")

				-- Name of command
				local commandName = commandDetails[1]

				-- Name of player
				local playerName = commandDetails[2]

				-- Is name of player and name of command valid?
				if table.find(commandsList, commandName) and Players:FindFirstChild(playerName) then
					local SmiteBlock = RS:WaitForChild("commandObjects"):WaitForChild("Smite"):Clone()
					SmiteBlock.Parent = game.Workspace

					local PlayerObject = Players:FindFirstChild(playerName)

					local character = PlayerObject.Character

					local ThunderSound = Instance.new("Sound", game.Workspace)
					ThunderSound.SoundId = "rbxassetid://357559831"

					ThunderSound:Play()
					SmiteBlock.Transparency = 1

					task.wait(1)

					SmiteBlock.Transparency = 0

					SmiteBlock.Position = character:WaitForChild("HumanoidRootPart").Position

					local Fire = RS:WaitForChild("Effects"):WaitForChild("Fire"):Clone()
					Fire.Parent = character:WaitForChild("HumanoidRootPart")

					BadgeService:AwardBadge(player.UserId, 2125214032)

					for i, v in pairs(character:GetChildren()) do
						if v:IsA("Part") or v:IsA("UnionOperation") then
							v.Color = Color3.new(0,0,0)
						end
					end

					task.wait(0.2)

					SmiteBlock:Destroy()
				end
			end
		end
	end)
end)

Oh don’t worry, I ended up fixing it in another topic, though I forgot what it was called so I can’t link it…

1 Like