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

[SOLVED] How to change image in all player GUI if a single player touch a part??

Asked by 2 years ago
Edited 2 years ago

I want it so that if a person touch a part in workspace then all of the players GUI will be affected.

If a single player have a keycard ang he/she touch a door for example, then all of the player GUI will change image, but if that player touch while not holding or don't have a keycard on backpack then nothing will happen.

0
use a remote event ZeroToH3ro 82 — 2y
0
I know that I need to use a remote event, however I'm not really good at scripting. Can you do me a favor? AltairCelestia 47 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

To do this you would need to use remote events as mentioned

First you have to check if a part is being touched while a keycard is equipped

Script in the part:

local part = script.Parent
local remote = -- path to a remote event

-- touched connection
part.Touched:Connect(function(hit)
    -- check if what's hitting the part is a player
    if hit.Parent:FindFirstChild("Humanoid") then
        -- check if the player has a keycard
        -- equipped tools get parented to the character

        local character = hit.Parent

        -- the "Keycard" is the tool name we're searching for
        if character:FindFirstChild("Keycard") then
            -- if we're in here it means the player has the keycard equipped
            -- and touched the part. Now we have to use remotes to change
            -- everyone's UI
            remote:FireAllClients()
        end
    end
end)

Now we've confirmed a player has touched and part with a keycard, and we've fired a remote to all the clients in the game. We now have to set up a script to listen for that remote being triggered and change the UI image accordingly.

Local script in the GUI:

local gui = script.Parent 
local imageLabel = gui:WaitForChild("ImageLabel") -- path to image
local remote = -- path to the same remote as above

remote.OnClientEvent:Connect(function()
    imageLabel.Image = "" -- change the image to a new image
end)

And that should do it

0
Wow, I read it and yeah will will absolutely work since I understand basic and some advance scripting. Thanks. I'll put your name on credit when I publish it. AltairCelestia 47 — 2y
0
Sorry but, it said AltairCelestia 47 — 2y
0
It said "Touched is not a valid member of Model "Workspace.Map.Doors.ExitDoor1.Condition1" AltairCelestia 47 — 2y
0
It works now, I didn't know that I can't use a group as part, my bad AltairCelestia 47 — 2y
0
No problem, glad to have helped! SimpleFlame 255 — 2y
Ad

Answer this question