Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
2
Answered by
Arkrei 389 Moderation Voter
4 years ago
Edited 4 years ago

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)

Ad
Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
4 years ago
Edited 4 years ago

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)

Answer this question