I am trying to create a custom admin bar with working admin commands. Right now, I'm trying to make a damage command. The problem is in the server script, line 10.
I'll add the server script and local script (if needed), may anyone tell me what's wrong with my code?
--LOCAL SCRIPT-- wait() local rf = game:FindFirstChild("ReplicatedStorage").RemoteEvents.apcmd local ok = script.Parent.submitcmd local bar = script.Parent.cmdbar ok.MouseButton1Click:Connect(function() rf:FireServer(bar.Text) end)
--SERVER SCRIPT-- local plrs = game:GetService("Players") local rf = game.ReplicatedStorage.RemoteEvents.apcmd rf.OnServerEvent:Connect(function(player,cmd) if cmd:sub(1,7) == "damage " then local plr = plrs:FindFirstChild(cmd:sub(8)) game.Workspace[plr.Name].Humanoid.Health = game.Workspace[plr.Name].Humanoid.Health - cmd:sub(10) end end)
ok my second answer. I see the problem.
cmd = "damage "..PlayerName..Damage
In your script use sub(8) that will be PlayerName..Damage so that not the player name.
now try this script.
--SERVER SCRIPT-- local plrs = game:GetService("Players") local rf = game.ReplicatedStorage.RemoteEvents.apcmd rf.OnServerEvent:Connect(function(player,cmd) if cmd:sub(1,7) == "damage " then local plr = nil for _,v in pairs(plrs:GetPlayers()) for i = 8,40,1 do if cmd:sub(8,i) == v.Name then plr = v end end end if plr ~= nil then plr.Character.Humanoid.Health = plr.Character.Humanoid.Health - cmd:sub(10) else print("No Player Found") end end end)