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

How would i find "plrName" it thinks im trying to find plrname in W but it's actually a variabel?

when you enter a name in the textbox it will get what it says and try to find it in the workspace I have defined it by "plrName" but it searches for the actual name not from the variable any help

local remote = game.ReplicatedStorage.Admin.killplr
remote.OnServerEvent:Connect(function(player)
		local plrName = player.PlayerGui.zxcxzx.Trolling_UI.PlrName.Text
		
		workspace[plrName].Head:Destroy()
end)

yes I have another script but it's not inportant

2 answers

✓ Accepted answer

Well in your script you are searching for player.PlayerGui.zxcxzx.Trolling_UI.PlrName.Text which obviously wont be a valid member on the workspace duh.

What you can do since you used the player argument in the remote event, you can do local Character = player.Character which will access the players character held in the workspace or from "player" you can use player.Name to access the playername and use workspace:FindFirstChild(player.Name)

You're trying to get the targeted player by getting it from a textlabel in the GUI. This just won't work and it's messy.

Instead, how about we fire the remote event and have the arguments use the targeted player?

local remote = game.ReplicatedStorage.Admin.killplr
remote.OnServerEvent:Connect(function(TargetPlayer)
	local Character = workspace:FindFirstChild(TargetPlayer)
	if Character and game:GetService("Players"):GetPlayerFromCharacter(Character) then
		Character.Humanoid.Health = 0
	end
end)

If we were to fire it, it'd be something like this:

local remote = game.ReplicatedStorage.Admin.killplr

remote:FireServer(PlrName.Text)

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