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

Removing function after player's death?

Asked by 5 years ago
Edited 5 years ago

I KNOW KEYDOWN IS DEPRECATED!!!

Alright, after more help I could do it and do my script. Now, I'd like to make the script work again when the caster or the objective dies. If you are new and you haven't seen my old question that's what I've done thanks to this great community:

-Choosing a player with Mouse -Pressing Z -Deactivating a script located in their playergui

And that's done with the following script:

local players = game:GetService("Players")
local mouse = game.Players.LocalPlayer:GetMouse()
local advertisement = game.Players.LocalPlayer.PlayerGui.Erasure:WaitForChild("Advertisement")
local nome = ""

mouse.KeyDown:connect(function(k)
k = k:lower()
if k == 'z' then
        --This makes appear a textlabel that says his script has been deactivated
    if game.Players.LocalPlayer.Backpack.ErasedValue.Value == "true" then
        local target = mouse.Target
        local humanoid = target.Parent:FindFirstChild("Humanoid")
        if humanoid then
        local character = humanoid.Parent
        local nomeplayer = players:GetPlayerFromCharacter(character)
        local nome = humanoid

        advertisement.Visible = true
        advertisement.TextLabel.BackgroundTransparency = 0.2
        advertisement.TextLabel.TextTransparency = 0.2
        wait(0.7)
        advertisement.Visible = true
        advertisement.TextLabel.BackgroundTransparency = 0.4
        advertisement.TextLabel.TextTransparency = 0.4
        wait(0.7)
        advertisement.TextLabel.BackgroundTransparency = 0.6
        advertisement.TextLabel.TextTransparency = 0.6
        wait(0.7)
        advertisement.TextLabel.BackgroundTransparency = 0.8
        advertisement.TextLabel.TextTransparency = 0.8
        wait(0.7)
        advertisement.TextLabel.BackgroundTransparency = 1
        advertisement.TextLabel.TextTransparency = 1
        wait(0.7)
        advertisement.Visible = false

               --That's the new thing, it didn't work though. Help, please?
        if nome.Health >= 0 then
            nomeplayer.Backpack.ErasedValue.Value = "false"
        elseif game.Players.LocalPlayer.Character.Humanoid.Health >= 0 then
            nomeplayer.Backpack.ErasedValue.Value = "false"
        end
        end

    else
    --This deactivates other people's script.
    local target = mouse.Target
    local humanoid = target.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local character = humanoid.Parent
        local nomeplayer = players:GetPlayerFromCharacter(character)
        local nome = nomeplayer
        if nomeplayer.Backpack.ErasedValue.Value == "false" then
          nomeplayer.Backpack.ErasedValue.Value = "true"
        end
    end
    end
end
end
end)


I count on you this time too! Thanks for your help.

0
KeyDown is deprecated. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

This won't work because you’re trying to modify objects inside another player’s Backpack. You can’t modify another client's PlayerGui, PlayerScripts, or Backpack from a LocalScript. You’ll need a RemoteEvent to access it.

Ad

Answer this question