Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

LocalPlayer GUI problem; shows up for everyone. How can I fix it?

Asked by 3 years ago

My code is quite long, as opposed to what's normally seen here so any help with it and anyone willing to read it will be appreciated.

The part I'm having trouble with is under the GUI section. When someone touches the door sensor, the GUI pops up on everyone's screen. I want to make it only pop up on the toucher's screen. What have I done wrong?

-----[General Variables]-----
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
TaskValue = game.ReplicatedStorage.System.Task

Sensors = {
    game.Workspace["Entrance Door"].Sensor
}
-----------------------------
-----[Debounce]-----
OpenEntranceDoorDebounce = false
--------------------
-----[GUI]-----
function DisplayGUI(Task)
    script.Parent.Frame:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 1, true)
    script.Parent.Frame.TextButton.Text = Task
end

function HideGUI()
    script.Parent.Frame:TweenPosition(UDim2.new(0, 0, -0.3, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 1, true)
end

for i,v in ipairs(Sensors) do
    v.Touched:connect(function (Part)
        if Part.Name == "Torso" then
            if v.Parent.Name == "Entrance Door" then
                TaskValue = "Entrance Door"
                DisplayGUI("Open Entrance Door")
            end
        end
        v.TouchEnded:connect(function ()
            TaskValue = nil
            HideGUI()
        end)
    end)
end
---------------


-----[Entrance Door]-----
EntranceDoor = game.Workspace["Entrance Door"]
EntranceDoorMotors = {
    EntranceDoor.Handle2.HingeConstraint;
    EntranceDoor.Handle1.HingeConstraint;
    EntranceDoor.Door.HingeConstraint
}
function OpenEntranceDoor()
    for i,v in ipairs(EntranceDoorMotors) do
        if v.Parent.Name ~= "Door" then
            v.AngularVelocity = 3
        end
    end
    wait(2)
    for i,v in ipairs(EntranceDoorMotors) do
        if v.Parent.Name ~= "Door" then
            v.AngularVelocity = 0
        end
    end
    wait(1)
    EntranceDoorMotors[3].TargetAngle = 179
    wait(5)
    EntranceDoorMotors[3].TargetAngle = 0
    wait(1)
    for i,v in ipairs(EntranceDoorMotors) do
        if v.Parent.Name ~= "Door" then
            v.AngularVelocity = -3
        end
    end
    wait(5)
    for i,v in ipairs(EntranceDoorMotors) do
        if v.Parent.Name ~= "Door" then
            v.AngularVelocity = 0
        end
    end
end
-------------------------

-----[General]-----
Mouse.KeyDown:connect(function (key)
    if key == "q" then
        if TaskValue == "Entrance Door" then
            if OpenEntranceDoor == true then return end
            OpenEntranceDoorDebounce = true
            OpenEntranceDoor()
            OpenEntranceDoorDebounce = false
        end
    end
end)
-------------------

1 answer

Log in to vote
2
Answered by
eLunate 5104 Trusted Moderation Voter Community Moderator
3 years ago

You checked for everyone touching.
"Oh, that's not mine..."

Instead of simply checking whether a Torso touches, check whether the part which touches belongs to the Player's character. And then show the GUI. Alternatively, check for when the player touches something, instead of for when something is touched by the player.

0
I have no idea why you got downvoted. Anyhow, I went an inverse route and checked that the person touched by the door is x after screwing around SquirreIOnToast 309 — 3y
Ad

Answer this question