Local script changing part properties for whole server, not just client

The code works perfectly but I just tried it with my alt and it runs server side… why???

This is a snippet of the code.

local outside = workspace:WaitForChild("ClubOutsideView")

outside.Touched:Connect(function(hit)
	show = true
	doortouched = false
	backpart.Transparency = 1
	backpart.CanCollide = false
	wait()
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then

		for _, part in pairs(firstfolder:GetChildren()) do
			part.Transparency = .011
			part.CanCollide = false
			part.CastShadow = false
		end
		for _, part in pairs(sign:GetChildren()) do
			part.Transparency = 0
			part.CanCollide = true
			part.CastShadow = true
		end
		for _, part in pairs(glassfolder:GetChildren()) do
			part.Transparency = .9999
			part.CanCollide = false
			part.CastShadow = false
		end
		for _, part in pairs(folder:GetChildren()) do
			part.Transparency = 1
			part.CanCollide = false
			part.CastShadow = false
		end
		for _, part in pairs(lights:GetChildren()) do
			part.PointLight.Enabled = false
		end
	end
end)
2 Likes

I’m still having this issue. I disabled all plugins and other scripts. When my player touches a part, it changes transparency for everyone in the server not just me.

1 Like

Just to confirm this is all in a LocalScript right?

Yes.

it executes the code when it got touched. Doesnt matter who touched it.

Do this

local outside = workspace:WaitForChild("ClubOutsideView")
local  player = game.Players.LocalPlayer

outside.Touched:Connect(function(hit)
	show = true
	doortouched = false
	backpart.Transparency = 1
	backpart.CanCollide = false
	wait()
	local player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player2 == player then

		for _, part in pairs(firstfolder:GetChildren()) do
			part.Transparency = .011
			part.CanCollide = false
			part.CastShadow = false
		end
		for _, part in pairs(sign:GetChildren()) do
			part.Transparency = 0
			part.CanCollide = true
			part.CastShadow = true
		end
		for _, part in pairs(glassfolder:GetChildren()) do
			part.Transparency = .9999
			part.CanCollide = false
			part.CastShadow = false
		end
		for _, part in pairs(folder:GetChildren()) do
			part.Transparency = 1
			part.CanCollide = false
			part.CastShadow = false
		end
		for _, part in pairs(lights:GetChildren()) do
			part.PointLight.Enabled = false
		end
	end
end)

this checks if player have touched the part and not some other player in the game

It’s still changing for all players unfortunately.

is it on server side?? if yes then fire event to the client and change the property on client side.

How I would go about it is,

  1. Create a script in ServerScriptStorage
  2. Create a Remote Event
  3. Create a LocalScript in StarterPlayerScripts
  4. Check in server script if the part is touched, if it is then use :FireClient(player)
  5. Use remoteEvent.OnClientEvent:Connect() to pick up the event and then adjust transparencies.

Right, but the reason I had it start from the client in the first place was because of the debounces, it makes sure the remoteevent only fires once per time the player touches it, and won’t loop while the player is still touching the part. I’m not sure how I could do that on server-side without it not firing for some people

you have to make sure whatever is touching the part, its reference to the player thats touching it

you do not have any checks whatsoever for that, hence why its playing for all clients

What do I add in to check that?

local part = game.Workspace.Part
local Player = game.Players.LocalPlayer

part.Touched:Connect(function(touched)
	if touched.Parent:FindFirstChild("Humanoid") and Player.Name == touched.Parent.Name then
		
		--//--
		--insert code here
		
		
	end
end)


this should fully fix your problem.
add your code below the lines, and you can add debounce if you’d like.

2 Likes

Thank you so much you’re a life saver!!!

nooooooooooooooooooo problem!! :grinning:

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