Issue with kill block

Hello,
I am making a kill block that should only kill you if a gui contains certain text, why isnt this working?

local Part = script.Parent
local gui = game.StarterGui.ScreenGui.NoobMode.TextButton.Text

local function PlayerTouched(Kill)
	local Parent = Kill.Parent
	if game.Players:GetPlayerFromCharacter(Parent) then
		if gui == "Noob Mode: Disabled" then
		Parent.Humanoid.Health = 0
	end
end

Part.Touched:connect(PlayerTouched)
1 Like

Heya! The reason for why this is happening is cause looking at this line here:

You’re only getting the StarterGui, and not the actual Player’s GUI

You see, the StarterGui is replicated to the server while the PlayerGui is replicated to everyone’s individual client

To fix this, you should get the Player’s GUI as well by creating a couple of variables (Defining the Player, PlayerGui and such)

local Part = script.Parent

local function PlayerTouched(Kill)

	local Parent = Kill.Parent
    local Player = game.Players:GetPlayerFromCharacter(Parent)
    if Player then
        local PlayerGui = Player:WaitForChild("PlayerGui")
        local TextLabel = PlayerGui:WaitForChild("ScreenGui").NoobMode.TextButton

		if TextLabel.Text == "Noob Mode: Disabled" then
		    Parent.Humanoid.Health = 0
        end
	end
end

Part.Touched:Connect(PlayerTouched)

I’m assuming the Gui Script that handles the Text is on a Server Script? If not, then yeah use RemoteEvents as @XdJackyboiiXd21 mentioned

Gui has to be the instance, not the text property. It’s only saving the value of the text as the variable, it won’t change if the gui’s Text property is changed.

Change your variable to:

local gui = game.StarterGui.ScreenGui.NoobMode.TextButton

Then change your if statement to:

if gui.Text == "Noob Mode: Disabled" then

Also little FYI, you’re missing an end. You should also change :connect to :Connect as the former is deprecated.

For this to work, you will also have to change the text on the server. If you just change the text button’s text on the client, the server won’t be able to see it so you would have to use remote events for it.

Hm, it still does not seem to be working.

1 Like

Is your script a server script or a local script? Any output errors?

1 Like

It’s a server script, doesn’t show any errors.

1 Like

The GUI script is in a local script, it is being used as a client setting, that’s why I am not using a RemoteEvent.

1 Like

Ah okay, you’d probably have to switch it to a local script and try putting it in StarterPlayerScripts. Try to keep UIs on the client side and if you need to get information from or give information to the server, you can do that with remotes.

You should also change this to game:GetService('Players').LocalPlayer:WaitForChild('ScreenGui').NoobMode.TextButton.

Then instead of making a script in every single part, you can use a loop to create the connections, you can disconnect them if you need to as well. Note that each kill part has to be identifiable in some way, such as a name, putting a child into the part or giving the part an attribute.

local textButton = game:GetService('Players').LocalPlayer:WaitForChild('ScreenGui').NoobMode.TextButton
local noobKillParts = {}
local mode = 'Noob'

textButton.Changed:Connect(function()
    if textButton.Text == 'Noob Mode: Disabled' then -- Listen for the button to change, then if the string matches, set the mode to Noob.
        mode = 'Noob'
    else
        mode = 'Pro'
    end
end)

for i,v in pairs(workspace:GetDescendants()) do
    if v:IsA('BasePart') then
        if v.Name == 'NoobKillPart' -- I'm assuming you'd go with a name here, I'm calling it 'NoobKillPart'
            noobKillParts[v] = v.Touched:Connect(function(hit)
                if mode == 'Noob' then -- If the mode is Noob then
                    local player = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent) -- Get the player from the hit part's parent
                    if player then
                        local humanoid = hit.Parent:FindFirstChild('Humanoid')
                        humanoid.Health = 0
                     end
                 end
             end)
          end
       end
    end
end

-- Then if you wanted to disable all of the noob kill parts,

for i,v in pairs(noobKillParts) do
    v:Disconnect()
end

-- Or if you want to disable a specific noob kill part,

local myPartToDisable = workspace.NoobKillPart
noobKillParts[myPartToDisable]:Disconnect() -- Since we made the index the instance, we can easily index the connection inside of the noobKillParts table.
1 Like

local Part = script.Parent
local gui = game.StarterGui.ScreenGui.NoobMode.TextButton.Text
local function PlayerTouched(Kill)
local Parent = Kill.Parent
if game.Players:GetPlayerFromCharacter(Parent) then
if gui == “Noob Mode: Disabled” then
Kill.Parent.Humanoid.Health = 0
end
end
end
Part.Touched:connect(PlayerTouched)

Also put this as a script into the part, let me know if this works.

1 Like

No, it does not seem to be working

local Part = script.Parent
Part.Touched:Connect(function(Hit)
      if Hit and Hit.Parent:FindFirstChildOfClass('Humanoid') then
            local Player = game:GetService('Players'):GetPlayerFromCharacter(Hit.Parent)
            if Player then
                   if Player.PlayerGui.ScreenGui.NoobMode.TextButton.Text == "Noob Mode: Disabled" then
                        hit.Parent:BreakJoints()
                  end
            end
      end
end)

Script in the part

Hm, this didn’t seem to work either

I’ll repro and see if it works.

1 Like

why is it starter gui?, this should be player gui.

simply put it in the script where the gui is, and do

local gui = script.parent
2 Likes

Can you send your game file, please?