hey guys, im trying to get the player from the text on my ui and if it does then to kill the player. but if i select my own name i dont want the script to run. i appreciate any help ty!
script:
yes.MouseButton1Click:Connect(function()
plrchoiceUI.Enabled = false
if selectedButton then
selectedButton.BackgroundColor3 = unselectedColor
end
if selectedButton then
local findPlr:Player = plrs:FindFirstChild(selectedButton.Text)
if findPlr then
plrcheckEvent:FireClient(findPlr)
end
end
end)
local script:
local plrcheckEvent = game.ReplicatedStorage:WaitForChild("plrcheckEvent")
plrcheckEvent.OnClientEvent:Connect(function(findplr)
if findplr.Character.Humanoid.Health > 0 then
findplr.Character.Humanoid.Health = 0
end
end)
this works and kills other players but i dont want it to kill my own if i select it:
yes.MouseButton1Click:Connect(function()
plrchoiceUI.Enabled = false
if selectedButton then
selectedButton.BackgroundColor3 = unselectedColor
end
if selectedButton then
local findPlr:Player = plrs:FindFirstChild(selectedButton.Text)
if findPlr then
if findPlr.Character.Humanoid.Health > 0 then
findPlr.Character.Humanoid.Health = 0
end
end
end
end)
I’m actually curious. Why are you detecting the click on the server and then firing a remote event to the client? It should be the other way around. Doing that will allow you to just use:
local Player = game:GetService("Players").LocalPlayer
my lordy, several things are funky bro.
Legit things that are supposed to be on local is on the server, and things that are on the server are on the local??
broski–huh
You shouldn’t be doing this on the local
Server:
-- Server script
local plrcheckEvent = game.ReplicatedStorage:WaitForChild("plrcheckEvent")
plrcheckEvent.OnServerEvent:Connect(function(player, findplr)
if findplr and findplr ~= player and findplr.Character and findplr.Character:FindFirstChild("Humanoid") then
findplr.Character.Humanoid.Health = 0
end
end)
Local:
-- Local script
yes.MouseButton1Click:Connect(function()
plrchoiceUI.Enabled = false
if selectedButton then
selectedButton.BackgroundColor3 = unselectedColor
end
if selectedButton then
local findPlr = plrs:FindFirstChild(selectedButton.Text)
if findPlr and findPlr ~= game.Players.LocalPlayer then
plrcheckEvent:FireServer(findPlr)
end
end
end)
yes u are indeed right. i suppose its my chaotic inexperience really. i tried to get my player from a local script. ahh long story, im just chaotic LOL.
this is what i tried:
local:
local getPlr = game.ReplicatedStorage:WaitForChild("getPlr")
local myPlr = game.Players.LocalPlayer
getPlr:FireServer(myPlr)
script:
yes.MouseButton1Click:Connect(function()
plrchoiceUI.Enabled = false
if selectedButton then
selectedButton.BackgroundColor3 = unselectedColor
end
if selectedButton then
local findPlr:Player = plrs:FindFirstChild(selectedButton.Text)
if findPlr then
getPlr.OnServerEvent:Connect(function(myPlayer)
if myPlayer.Name == findPlr then
print("player name is = to player name in list, returning")
end
if findPlr.Character.Humanoid.Health > 0 then
findPlr.Character.Humanoid.Health = 0
end
end)
end
end
end)
You’re setting the myPlayer to the player parameter, so it would actually be (plr, myPlayer) to actually get the variable.
as for this:
if you’re dead-set on doing it that way, change findPlr to findPlr.Name
and don’t forget to add return in the if condition, it’ll keep on running if you left it like that.
bro im telling u. im all over the place rofl . i like the gif btw.
so i took a lot of ur advice and its defo optimized better but its still killing my player . my selectedbutton is on the server script and everything is messed up pretty much but this is what i tried:
local script:
local plrchoiceUI = script.Parent.plrChoiceUI
local plrcheckEvent = game.ReplicatedStorage:WaitForChild("plrcheckEvent")
local yes = plrchoiceUI.Frame.yes
local myPlr = game.Players.LocalPlayer
yes.MouseButton1Click:Connect(function()
plrchoiceUI.Enabled = false
plrcheckEvent:FireServer(myPlr)
end)
script:
plrcheckEvent.OnServerEvent:Connect(function(myplr)
plrchoiceUI.Enabled = false
if selectedButton then
selectedButton.BackgroundColor3 = unselectedColor
end
if selectedButton then
local findPlr = plrs:FindFirstChild(selectedButton.Text)
if findPlr and findPlr ~= myplr.Name then
if findPlr.Character.Humanoid.Health > 0 then
findPlr.Character.Humanoid.Health = 0
end
end
end
end)
EDIT: NVM it works. i had to do: findPlr ~= myplr.Name → findPlr ~= myplr. tysm for ur help man!!!