Making a part transparent for one player

So I am trying to make a guess the logo type game. The problem is, for the minigame I am trying to make, I only want the person who actually guessed the logo to be allowed through the door instead of everybody. I have this script in a regular script:

local image = script.Parent.Check.ImageLabel
door = script.Parent
function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	local decal = script.Parent:FindFirstChildOfClass('Decal')
msg = string.lower(msg) 
	local thecharacter = script.Parent.TheCharacter
	print(msg)
	print(thecharacter.Value)
	print(script.Parent.TheCharacter2.Value)
	if msg == string.lower(thecharacter.Value) or msg == string.lower(script.Parent.TheCharacter2.Value) then 
		local value = game.ReplicatedStorage.Value.Value
		if value == true then
			door.CanCollide = false 
			image.Visible = true
			image:TweenPosition(UDim2.new(0.3, 0,0.3, 0), "Out",1)
			door.Transparency = 0.7 
			decal.Transparency = 0.7

			wait(3) 
			image:TweenPosition(UDim2.new(1, 0,0.3, 0), "Out",1)
			wait(1)
			image.Visible = false
			image.Position = UDim2.new(-0.4, 0, 0.3, 0)
			door.CanCollide = true 
			door.Transparency = 0 
			decal.Transparency = 0
		end
end 
end 
game.Players.ChildAdded:connect(function(plr)
plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

Obviously, this script is going to make the door transparent for all players. How would I make it so the door is only opened for the player who guessed it?

Just a few things before you comment, I want it to be time efficient. I have over 1000 of these doors so I don’t feel like changing the name of every door. I am fine with copy and pasting the script over and over inside each part.

Fire a remote event to the client that makes the specific part transparent

1 Like

The problem with this is that I now need to specify the part that needs to become transparent because the script would be located in the server. This would be close to 2 days of copy, pasting, and changing values which I don’t feel like spending.

So what would be a more efficient method?

Also, im getting this error:

With this script:


local image = script.Parent.Check.ImageLabel
door = script.Parent
function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	local decal = script.Parent:FindFirstChildOfClass('Decal')
	msg = string.lower(msg) 
	local thecharacter = script.Parent.TheCharacter
	print(msg)
	print(thecharacter.Value)
	print(script.Parent.TheCharacter2.Value)
	if msg == string.lower(thecharacter.Value) or msg == string.lower(script.Parent.TheCharacter2.Value) then 
		local value = game.ReplicatedStorage.Value.Value
		if value == true then
			game.ReplicatedStorage.DoorEvent:FireClient()
		end
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

When calling FireClient() you must pass in the player, fixed:

local image = script.Parent.Check.ImageLabel
door = script.Parent
function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	local decal = script.Parent:FindFirstChildOfClass('Decal')
	msg = string.lower(msg) 
	local thecharacter = script.Parent.TheCharacter
	print(msg)
	print(thecharacter.Value)
	print(script.Parent.TheCharacter2.Value)
	if msg == string.lower(thecharacter.Value) or msg == string.lower(script.Parent.TheCharacter2.Value) then 
		local value = game.ReplicatedStorage.Value.Value
		if value == true then
			game.ReplicatedStorage.DoorEvent:FireClient(speaker)
		end
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)

Also you should be passing in the part to make transparent, in this case, you would pass in door after speaker (In the FireClient())

It’s really no different, since door is script.Parent in every script and that’s what your changing the transparency of, all you have to do is:

You really should be doing all of that in one script, but just looping through all the doors, an easier way than changing the names is just put every door in a Doors folder and loop through that

The problem now is that the local script located inside of the union is not receiving the script. Does it need to be inside the player? If it does, then i’ll need to find a new method because I don’t want to rename every door and then change every script for every door. Here’s the script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local image = script.Parent.Check.ImageLabel
door = script.Parent
local welcomePlayerEvent = ReplicatedStorage:WaitForChild("DoorEvent")
local decal = script.Parent:FindFirstChildOfClass('Decal')

local function onWelcomePlayerFired()
	print("received")
	door.CanCollide = false 
	image.Visible = true
	image:TweenPosition(UDim2.new(0.3, 0,0.3, 0), "Out",1)
	door.Transparency = 0.7 
	decal.Transparency = 0.7

	wait(3) 
	image:TweenPosition(UDim2.new(1, 0,0.3, 0), "Out",1)
	wait(1)
	image.Visible = false
	image.Position = UDim2.new(-0.4, 0, 0.3, 0)
	door.CanCollide = true 
	door.Transparency = 0 
	decal.Transparency = 0
end

welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)

First off, you didn’t listen, I told you you should pass the door in as a parameter and not have the door variable at the top of the local script. Also I just realized we will need to pass in the image and decal aswell. Local script should look like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local welcomePlayerEvent = ReplicatedStorage:WaitForChild("DoorEvent")

local function onWelcomePlayerFired(door, image, decal)
	print("received")
	door.CanCollide = false 
	image.Visible = true
	image:TweenPosition(UDim2.new(0.3, 0,0.3, 0), "Out",1)
	door.Transparency = 0.7 
	decal.Transparency = 0.7

	wait(3) 
	image:TweenPosition(UDim2.new(1, 0,0.3, 0), "Out",1)
	wait(1)
	image.Visible = false
	image.Position = UDim2.new(-0.4, 0, 0.3, 0)
	door.CanCollide = true 
	door.Transparency = 0 
	decal.Transparency = 0
end

welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)

Now second thing, local scripts don’t run as a descendant of the workspace. Place the local script in StarterPlayerScripts.

Now, your sever script must now also pass in the door, image, decal into the event. So your regular should be:

local image = script.Parent.Check.ImageLabel
door = script.Parent
function onChatted(msg, recipient, speaker) 
	local source = string.lower(speaker.Name) 
	local decal = script.Parent:FindFirstChildOfClass('Decal')
	msg = string.lower(msg) 
	local thecharacter = script.Parent.TheCharacter
	print(msg)
	print(thecharacter.Value)
	print(script.Parent.TheCharacter2.Value)
	if msg == string.lower(thecharacter.Value) or msg == string.lower(script.Parent.TheCharacter2.Value) then 
		local value = game.ReplicatedStorage.Value.Value
		if value == true then
			game.ReplicatedStorage.DoorEvent:FireClient(speaker, door, image, decal)
		end
	end 
end 
game.Players.ChildAdded:connect(function(plr)
	plr.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, plr) end) 
end)