I’m trying to make it so that instead of making it so if a player touches the part, it only disappears for them instead of the entire sever.
I’m not quite sure where to look to solve this, everything I see just tells me how to do what I’ve already done (change the parts properties for the server)
Here is my code:
local block = script.Parent
local debounce = true
block.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA('Humanoid')
if humanoid and debounce == true then
debounce = false
block.Transparency = 0.8
block.CanCollide = false
wait(3)
block.Transparency = 0
block.CanCollide = true
debounce = true
end
end)
I appreciate the solution, but I don’t think it would be very efficient because there will be a lot of these parts in the game and I don’t want everything to just disappear when you stand on a block, is there an alternative way where I can put the script inside the part or maybe a folder?
Its more efficient to do it this way than to have a script inside of each part. if you have multiple parts then just use a loop.
for i,v in pairs (workspace:GetChildren()) do
if v.Name == ‘Transparent Part’ and v:IsA(‘Part’) then
v.Transparency = 1
end
end
alternatively you could use an event and do sever to client. But just using a local script for this 1 thing is far more efficient than having 1 script inside of each part like youre wanting to. Like that would cause way more lag than you need. And when dealing with just player side things it has to be inside a local script. You cant have server script deal with solo player things unless its very case specific.
You can use a Player object to find the player who touched the part. You can then use Player.Character to find the Humanoid of the player, and then do the rest of your script as normal. local block = script.Parent
local debounce = true
block.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent) – get the player who touched the part
if player and debounce == true then
debounce = false