Help me pls fix script

Hello im did a mistake in a script and im dont know whats wrong.
My script:

function onTouched(hit) 
	if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then 
		if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor == script.Parent.TeamColor.Value then 
			game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(Key)
				if Key == "b" then
					game.Players.LocalPlayer.PlayerGui.Shop.Frame.Visible = true
				end
			end)
		end
	end 
end 

script.Parent.Touched:connect(onTouched)

Output error: Workspace.Part.Script:4: attempt to index nil with ‘GetMouse’

1 Like

This script stopped work when im rejoined roblox studio

ServerScripts cannot access client directly via Players, you’d need a LocalScript instead. Try it with a LocalScript that you gotta put for example in StarterGui. Then you’d need to use CollectionService unless you are using it for 1 part. (To listen to the .Touched event)

Reference:

Thanks you! Im try this right now.