Localscript works in the studio but not in the game

My local script is not working. I have not touched the localscript and derepenta now works in roblox studio but in the game it only works from time to time. And this one is reading all the players in the game.

In roblox studio

In game

This is the localscipt that is located in StarterPlayerScripts and so far it has not been giving me any errors

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

local MapaName = ReplicatedStorage:WaitForChild(“MapaName”)
local oldVal = nil

local Sound = game.SoundService.BotonSound

while wait() do
if MapaName.Value ~= oldVal then
wait(0.25)

  local MapaNameValue = MapaName.Value
  oldVal = MapaNameValue
  local Botons = MapaNameValue.Mapa.Obstaculos.ModelBotons:WaitForChild("Botons")

  for _, v in pairs(Botons:GetChildren()) do
  	v.Touched:Connect(function(hit)
  		if hit.Parent:FindFirstChild("Humanoid") then
  			if hit.Parent == game.Players.LocalPlayer.Character and v.playsound.Value == true then
  				
  				v.playsound.Value = false
  				
  				local Bloks = v:FindFirstChildWhichIsA("Folder")

  				for j, Part in pairs(Bloks:GetChildren()) do
  					Part.CanCollide = true
  					Part.Transparency = 0
  					Sound:play()
  				
  				end 
  			end
  		end
  	end)
  end

end
end

1 Like