How to make a part invisible for the player who clicked

Hey guys, i’m trying to make a part that, when clicked by a player, the part disappears only for him. My script so far (it’s a normal script):

local ck = script.Parent
local badgeservice = game:GetService("BadgeService")
local id = 2153785678

ck.MouseClick:Connect(function(player)
	if player.WitchesBrew.Value == 4 then
		print("hooray")
		badgeservice:AwardBadge(player.UserId,id)
		script.Parent.Parent:Destroy()
	else
		player.WitchesBrew.Value += 1
		print("added")
		script.Parent.Parent:Destroy()
	end
end)

(ignore the badge and the values part)

1 Like

assuming the part is the parent of ck (script.Parent.Parent)
you would need to make a new local script and place it in the same location as your normal script

in this local script you would put this code in

local ClickDetector = script.Parent
ClickDetector.MouseClick:Connect(function()
    ClickDetector.Parent.Transparency = 1
end)
1 Like

it didn’t work… if i put the normal script on the local it would change anything?

1 Like

LocalScripts don’t run in the workspace - you will have to use a RemoteEvent.

Instructions if needed
  1. Create a RemoteEvent in ReplicatedStorage named something along the lines of “HidePart”
  2. Create a LocalScript in StarterPlayerScripts - name doesn’t matter
  3. In the normal script, write:
local ck = script.Parent
local badgeservice = game:GetService("BadgeService")
local id = 2153785678

local hidePartEvent = game:GetService("ReplicatedStorage"):WaitForChild("HidePart")

ck.MouseClick:Connect(function(player)
	if player.WitchesBrew.Value == 4 then
		print("hooray")
		badgeservice:AwardBadge(player.UserId,id)
	else
		player.WitchesBrew.Value += 1
		print("added")
	end

    hidePartEvent:FireClient(player, script.Parent.Parent)
end)
  1. In the LocalScript, write:
local replicatedStorage = game:GetService("ReplicatedStorage")

local hidePartEvent = replicatedStorage:WaitForChild("HidePart")

local function onHidePartEvent(part)
    part:Destroy()
    -- part.LocalTransparencyModifier = 1 Instead of destroying it, you could also just make it transparent, but whichever is better
end

hidePartEvent.OnClientEvent:Connect(onHidePartEvent)
2 Likes

bro, thank you so much!
It worked as expected, and you saved my life! I really thank you.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.