Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

use a remote event

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?

1 answer

✓ Accepted answer

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

5 comments

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.

0

Sorry but, it said

0

It said "Touched is not a valid member of Model "Workspace.Map.Doors.ExitDoor1.Condition1"

0

It works now, I didn't know that I can't use a group as part, my bad

0

No problem, glad to have helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.