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

How do I fix this script that makes a player's GUI visible?

Asked by 5 years ago
Edited 5 years ago

This script is supposed to open/close a player's GUI via a remote function, depending on how close the player is (or isn't) to a particular block. It's in a model that is bought in a tycoon game.

The script runs perfectly when there is only one of the brick present in the game. Any more and the script breaks. Besides this, Output gave me nothing.

Can someone help me? Here's the script:

exited = {}


while wait() do
    local armsPos = script.Parent.Torso.Position



    for _,v in pairs(game.Players:GetPlayers()) do

        if  v.Character ~= nil and (armsPos - v.Character.Torso.Position).magnitude <= 10 and not exited[v.Name] then
            game.ReplicatedStorage.ShowArmory:FireClient(v,true)
            exited[v.Name] = true       
        elseif v.Character ~= nil and (armsPos - v.Character.Torso.Position).magnitude > 10  then
            game.ReplicatedStorage.ShowArmory:FireClient(v,false)
            if exited[v.Name] then exited[v.Name] = nil end
        end
    end
end

If it matters, here is the section of the script, located in the GUI itself, that detects whether or not it should be visible.

game.ReplicatedStorage.ShowArmory.OnClientEvent:connect(function(val)
    gui.Enabled = val
end)

1 answer

Log in to vote
-1
Answered by
Vmena 87
5 years ago

In your for loop you have the following code:

for _,v in pairs(game.Players:GetPlayers()) do

You should have the following code:

for _,v in pairs(game.Players:GetChildren()) do

GetPlayers is not a valid function of Players, you still use GetChildren like you would all other objects.

Glad I could help!

0
it works with either line. CoolJohnnyboy 121 — 5y
Ad

Answer this question